2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const shared = require("./shared");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
module.exports = {
|
2018-03-19 23:39:42 +01:00
|
|
|
"names": [ "MD036", "no-emphasis-as-heading", "no-emphasis-as-header" ],
|
|
|
|
"description": "Emphasis used instead of a heading",
|
|
|
|
"tags": [ "headings", "headers", "emphasis" ],
|
2018-01-21 21:44:25 -08:00
|
|
|
"function": function MD036(params, onError) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const punctuation = params.config.punctuation || ".,;:!?";
|
|
|
|
const re = new RegExp("[" + punctuation + "]$");
|
2018-01-21 21:44:25 -08:00
|
|
|
function base(token) {
|
|
|
|
if (token.type === "paragraph_open") {
|
|
|
|
return function inParagraph(t) {
|
|
|
|
// Always paragraph_open/inline/paragraph_close,
|
|
|
|
// omit (t.type === "inline")
|
2018-04-27 22:05:34 -07:00
|
|
|
const children = t.children.filter(function notEmptyText(child) {
|
2018-01-21 21:44:25 -08:00
|
|
|
return (child.type !== "text") || (child.content !== "");
|
|
|
|
});
|
|
|
|
if ((children.length === 3) &&
|
|
|
|
((children[0].type === "strong_open") ||
|
|
|
|
(children[0].type === "em_open")) &&
|
|
|
|
(children[1].type === "text") &&
|
|
|
|
!re.test(children[1].content)) {
|
|
|
|
shared.addErrorContext(onError, t.lineNumber,
|
|
|
|
children[1].content);
|
|
|
|
}
|
|
|
|
return base;
|
|
|
|
};
|
|
|
|
} else if (token.type === "blockquote_open") {
|
|
|
|
return function inBlockquote(t) {
|
|
|
|
if (t.type !== "blockquote_close") {
|
|
|
|
return inBlockquote;
|
|
|
|
}
|
|
|
|
return base;
|
|
|
|
};
|
|
|
|
} else if (token.type === "list_item_open") {
|
|
|
|
return function inListItem(t) {
|
|
|
|
if (t.type !== "list_item_close") {
|
|
|
|
return inListItem;
|
|
|
|
}
|
|
|
|
return base;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return base;
|
|
|
|
}
|
2018-04-27 22:05:34 -07:00
|
|
|
let state = base;
|
2018-01-21 21:44:25 -08:00
|
|
|
params.tokens.forEach(function forToken(token) {
|
|
|
|
state = state(token);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|