Handle implicit close fence in MD031/blanks-around-fences to avoid null-dereference.

This commit is contained in:
David Anson 2020-10-16 14:08:42 -07:00
parent 9afd4e1ab5
commit 392cc287e6
2 changed files with 13 additions and 5 deletions

View file

@ -21,7 +21,11 @@ module.exports = {
if ((includeListItems || !inItem) && if ((includeListItems || !inItem) &&
((onTopFence && !isBlankLine(lines[i - 1])) || ((onTopFence && !isBlankLine(lines[i - 1])) ||
(onBottomFence && !isBlankLine(lines[i + 1])))) { (onBottomFence && !isBlankLine(lines[i + 1])))) {
const [ , prefix ] = line.match(codeFencePrefixRe); const [ , prefix ] = line.match(codeFencePrefixRe) || [];
const fixInfo = (prefix === undefined) ? null : {
"lineNumber": i + (onTopFence ? 1 : 2),
"insertText": `${prefix}\n`
};
addErrorContext( addErrorContext(
onError, onError,
i + 1, i + 1,
@ -29,10 +33,7 @@ module.exports = {
null, null,
null, null,
null, null,
{ fixInfo);
"lineNumber": i + (onTopFence ? 1 : 2),
"insertText": `${prefix}\n`
});
} }
}); });
} }

View file

@ -57,3 +57,10 @@ Text
fence {MD031:56} {MD031:58} fence {MD031:56} {MD031:58}
``` ```
1. Item 1. Item
Text
1. Text
```shell
fence {MD031:64} {MD031:65} {MD032:65} {MD040:66}
```