mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD037/no-space-in-emphasis to report left+right errors only once.
This commit is contained in:
parent
737126cf93
commit
dc8e746cd2
2 changed files with 47 additions and 24 deletions
44
lib/md037.js
44
lib/md037.js
|
|
@ -13,31 +13,37 @@ module.exports = {
|
|||
"tags": [ "whitespace", "emphasis" ],
|
||||
"function": function MD037(params, onError) {
|
||||
forEachInlineChild(params, "text", (token) => {
|
||||
const { content, lineNumber } = token;
|
||||
const columnsReported = [];
|
||||
[ leftSpaceRe, rightSpaceRe ].forEach((spaceRe, index) => {
|
||||
let match = null;
|
||||
while ((match = spaceRe.exec(token.content)) !== null) {
|
||||
while ((match = spaceRe.exec(content)) !== null) {
|
||||
const [ fullText, marker ] = match;
|
||||
const line = params.lines[token.lineNumber - 1];
|
||||
const line = params.lines[lineNumber - 1];
|
||||
if (line.includes(fullText)) {
|
||||
const text = fullText.trim();
|
||||
const column = line.indexOf(text) + 1;
|
||||
const length = text.length;
|
||||
const markerLength = marker.length;
|
||||
const emphasized = text.slice(markerLength, length - markerLength);
|
||||
const fixedText = `${marker}${emphasized.trim()}${marker}`;
|
||||
addErrorContext(
|
||||
onError,
|
||||
token.lineNumber,
|
||||
text,
|
||||
index === 0,
|
||||
index !== 0,
|
||||
[ column, length ],
|
||||
{
|
||||
"editColumn": column,
|
||||
"deleteCount": length,
|
||||
"insertText": fixedText
|
||||
}
|
||||
);
|
||||
if (!columnsReported.includes(column)) {
|
||||
const length = text.length;
|
||||
const markerLength = marker.length;
|
||||
const emphasized =
|
||||
text.slice(markerLength, length - markerLength);
|
||||
const fixedText = `${marker}${emphasized.trim()}${marker}`;
|
||||
addErrorContext(
|
||||
onError,
|
||||
lineNumber,
|
||||
text,
|
||||
index === 0,
|
||||
index !== 0,
|
||||
[ column, length ],
|
||||
{
|
||||
"editColumn": column,
|
||||
"deleteCount": length,
|
||||
"insertText": fixedText
|
||||
}
|
||||
);
|
||||
columnsReported.push(column);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue