mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD049/emphasis-style and MD050/strong-style to not report intraword asterisks/underscores as violations because exchanging either alters meaning (fixes #789).
This commit is contained in:
parent
7005a8a438
commit
0006636f75
8 changed files with 77 additions and 22 deletions
|
|
@ -5,10 +5,13 @@
|
|||
const { addError, emphasisOrStrongStyleFor } = require("../helpers");
|
||||
const { filterByTypes, tokenIfType } = require("../helpers/micromark.cjs");
|
||||
|
||||
const intrawordRe = /\w/;
|
||||
|
||||
const impl =
|
||||
(params, onError, type, asterisk, underline, style = "consistent") => {
|
||||
const { lines, parsers } = params;
|
||||
const emphasisTokens =
|
||||
filterByTypes(params.parsers.micromark.tokens, [ type ]);
|
||||
filterByTypes(parsers.micromark.tokens, [ type ]);
|
||||
for (const token of emphasisTokens) {
|
||||
const { children } = token;
|
||||
const childType = `${type}Sequence`;
|
||||
|
|
@ -20,19 +23,29 @@ const impl =
|
|||
style = markupStyle;
|
||||
}
|
||||
if (style !== markupStyle) {
|
||||
for (const sequence of [ startSequence, endSequence ]) {
|
||||
addError(
|
||||
onError,
|
||||
sequence.startLine,
|
||||
`Expected: ${style}; Actual: ${markupStyle}`,
|
||||
undefined,
|
||||
[ sequence.startColumn, sequence.text.length ],
|
||||
{
|
||||
"editColumn": sequence.startColumn,
|
||||
"deleteCount": sequence.text.length,
|
||||
"insertText": (style === "asterisk") ? asterisk : underline
|
||||
}
|
||||
);
|
||||
const underscoreIntraword = (style === "underscore") && (
|
||||
intrawordRe.test(
|
||||
lines[startSequence.startLine - 1][startSequence.startColumn - 2]
|
||||
) ||
|
||||
intrawordRe.test(
|
||||
lines[endSequence.endLine - 1][endSequence.endColumn - 1]
|
||||
)
|
||||
);
|
||||
if (!underscoreIntraword) {
|
||||
for (const sequence of [ startSequence, endSequence ]) {
|
||||
addError(
|
||||
onError,
|
||||
sequence.startLine,
|
||||
`Expected: ${style}; Actual: ${markupStyle}`,
|
||||
undefined,
|
||||
[ sequence.startColumn, sequence.text.length ],
|
||||
{
|
||||
"editColumn": sequence.startColumn,
|
||||
"deleteCount": sequence.text.length,
|
||||
"insertText": (style === "asterisk") ? asterisk : underline
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue