2021-10-24 06:54:58 +02:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2021-11-28 23:18:57 -08:00
|
|
|
const { addError, emphasisOrStrongStyleFor, forEachInlineChild,
|
|
|
|
getNextChildToken, getRangeAndFixInfoIfFound } = require("../helpers");
|
2021-10-24 06:54:58 +02:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
"names": [ "MD049", "emphasis-style" ],
|
|
|
|
"description": "Emphasis style should be consistent",
|
|
|
|
"tags": [ "emphasis" ],
|
|
|
|
"function": function MD049(params, onError) {
|
|
|
|
let expectedStyle = String(params.config.style || "consistent");
|
2021-11-28 23:18:57 -08:00
|
|
|
forEachInlineChild(params, "em_open", (token, parent) => {
|
2021-10-24 06:54:58 +02:00
|
|
|
const { lineNumber, markup } = token;
|
|
|
|
const markupStyle = emphasisOrStrongStyleFor(markup);
|
|
|
|
if (expectedStyle === "consistent") {
|
|
|
|
expectedStyle = markupStyle;
|
|
|
|
}
|
2021-11-28 23:18:57 -08:00
|
|
|
if (expectedStyle !== markupStyle) {
|
|
|
|
let rangeAndFixInfo = {};
|
|
|
|
const contentToken = getNextChildToken(
|
|
|
|
parent, token, "text", "em_close"
|
|
|
|
);
|
|
|
|
if (contentToken) {
|
|
|
|
const { content } = contentToken;
|
|
|
|
const actual = `${markup}${content}${markup}`;
|
|
|
|
const expectedMarkup = (expectedStyle === "asterisk") ? "*" : "_";
|
|
|
|
const expected = `${expectedMarkup}${content}${expectedMarkup}`;
|
|
|
|
rangeAndFixInfo = getRangeAndFixInfoIfFound(
|
|
|
|
params.lines, lineNumber - 1, actual, expected
|
|
|
|
);
|
|
|
|
}
|
|
|
|
addError(
|
|
|
|
onError,
|
|
|
|
lineNumber,
|
|
|
|
`Expected: ${expectedStyle}; Actual: ${markupStyle}`,
|
|
|
|
null,
|
|
|
|
rangeAndFixInfo.range,
|
|
|
|
rangeAndFixInfo.fixInfo
|
|
|
|
);
|
|
|
|
}
|
2021-10-24 06:54:58 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|