mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +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
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ A [reversed](link) example.
|
|||
|
||||
## Multiple spaces B
|
||||
|
||||
## No space C ####No space C ##
|
||||
## No space C ##
|
||||
|
||||
## No space D #### No space D##
|
||||
## No space D ##
|
||||
|
||||
## Multiple spaces E #### Multiple spaces E ##
|
||||
## Multiple spaces E ##
|
||||
|
||||
## Multiple spaces F #### Multiple spaces F ##
|
||||
## Multiple spaces F ##
|
||||
|
|
|
|||
|
|
@ -15,19 +15,19 @@ Bare <https://example.com> link
|
|||
|
||||
Space *inside* emphasis
|
||||
|
||||
Space `insidecode span
|
||||
Space `inside` code span
|
||||
|
||||
Space [inside](link) text
|
||||
|
||||
```
|
||||
```
|
||||
|
||||
space ``insideode
|
||||
space `inside` of `codeelements
|
||||
`space` inside `of` code `elements
|
||||
space ``inside`` of ``codelements
|
||||
``` embedded backtick
|
||||
embedded backtick```
|
||||
space ``inside`` code
|
||||
space `inside` of `code` elements
|
||||
`space` inside `of` code `elements`
|
||||
space ``inside`` of ``code`` elements
|
||||
`` ` embedded backtick``
|
||||
``embedded backtick` ``
|
||||
|
||||
some *space* in *some* emphasis
|
||||
some *space* in *some* emphasis
|
||||
|
|
@ -37,13 +37,11 @@ some __space__ in __some__ emphasis
|
|||
|
||||
Text
|
||||
text `code
|
||||
span
|
||||
span` text
|
||||
text.
|
||||
|
||||
Text
|
||||
text `code
|
||||
code
|
||||
span` text
|
||||
text.
|
||||
|
||||
|
|
@ -54,13 +52,9 @@ text.
|
|||
Text
|
||||
text ```code
|
||||
span code
|
||||
code
|
||||
span code
|
||||
span code``` text
|
||||
text
|
||||
text text ````code
|
||||
span code
|
||||
span
|
||||
span code
|
||||
span```` text
|
||||
text.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue