mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-01-05 23:48:49 +01:00
Fix broken MD020/MD021/MD038 scenarios.
This commit is contained in:
parent
677255a484
commit
33e3797084
5 changed files with 32 additions and 28 deletions
12
lib/md020.js
12
lib/md020.js
|
|
@ -12,7 +12,8 @@ module.exports = {
|
|||
"function": function MD020(params, onError) {
|
||||
forEachLine(lineMetadata(), (line, lineIndex, inCode) => {
|
||||
if (!inCode) {
|
||||
const match = /^(#+)(\s*)([^#]+?)(\s*)(\\?)(#+)(\s*)$/.exec(line);
|
||||
const match =
|
||||
/^(#+)(\s*)([^#]+?[^#\\])(\s*)((?:\\#)?)(#+)(\s*)$/.exec(line);
|
||||
if (match) {
|
||||
const [
|
||||
,
|
||||
|
|
@ -27,9 +28,8 @@ module.exports = {
|
|||
const leftHashLength = leftHash.length;
|
||||
const rightHashLength = rightHash.length;
|
||||
const left = !leftSpaceLength;
|
||||
const right =
|
||||
(!rightSpaceLength && (!rightEscape || (rightHashLength > 1))) ||
|
||||
(rightEscape && (rightHashLength > 1));
|
||||
const right = !rightSpaceLength || rightEscape;
|
||||
const rightEscapeReplacement = rightEscape ? `${rightEscape} ` : "";
|
||||
if (left || right) {
|
||||
const range = left ?
|
||||
[
|
||||
|
|
@ -49,9 +49,9 @@ module.exports = {
|
|||
range,
|
||||
{
|
||||
"editColumn": 1,
|
||||
"deleteLength": line.length,
|
||||
"deleteCount": line.length,
|
||||
"insertText":
|
||||
`${leftHash} ${content} ${rightEscape}${rightHash}`
|
||||
`${leftHash} ${content} ${rightEscapeReplacement}${rightHash}`
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ module.exports = {
|
|||
range,
|
||||
{
|
||||
"editColumn": 1,
|
||||
"deleteLength": length,
|
||||
"deleteCount": length,
|
||||
"insertText": `${leftHash} ${content} ${rightHash}`
|
||||
}
|
||||
);
|
||||
|
|
|
|||
18
lib/md038.js
18
lib/md038.js
|
|
@ -22,19 +22,29 @@ module.exports = {
|
|||
let rangeIndex = columnIndex - tickCount;
|
||||
let rangeLength = code.length + (2 * tickCount);
|
||||
let rangeLineOffset = 0;
|
||||
let fixIndex = columnIndex;
|
||||
let fixLength = code.length;
|
||||
const codeLines = code.split(newLineRe);
|
||||
const left = leftSpaceRe.test(code);
|
||||
const right = !left && rightSpaceRe.test(code);
|
||||
if (right && (codeLines.length > 1)) {
|
||||
rangeIndex = 0;
|
||||
rangeLineOffset = codeLines.length - 1;
|
||||
fixIndex = 0;
|
||||
}
|
||||
if (left || right) {
|
||||
const codeLinesRange = codeLines[rangeLineOffset];
|
||||
if (codeLines.length > 1) {
|
||||
rangeLength = codeLines[rangeLineOffset].length + tickCount;
|
||||
rangeLength = codeLinesRange.length + tickCount;
|
||||
fixLength = codeLinesRange.length;
|
||||
}
|
||||
const context = tokenLines[lineIndex + rangeLineOffset]
|
||||
.substring(rangeIndex, rangeIndex + rangeLength);
|
||||
const codeLinesRangeTrim = codeLinesRange.trim();
|
||||
const fixText =
|
||||
(codeLinesRangeTrim.startsWith("`") ? " " : "") +
|
||||
codeLinesRangeTrim +
|
||||
(codeLinesRangeTrim.endsWith("`") ? " " : "");
|
||||
addErrorContext(
|
||||
onError,
|
||||
token.lineNumber + lineIndex + rangeLineOffset,
|
||||
|
|
@ -43,9 +53,9 @@ module.exports = {
|
|||
right,
|
||||
[ rangeIndex + 1, rangeLength ],
|
||||
{
|
||||
"editColumn": rangeIndex + (left ? tickCount : 0) + 1,
|
||||
"deleteCount": rangeLength - (right ? tickCount : 0),
|
||||
"insertText": code.trim()
|
||||
"editColumn": fixIndex + 1,
|
||||
"deleteCount": fixLength,
|
||||
"insertText": fixText
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue