Fix broken MD020/MD021/MD038 scenarios.

This commit is contained in:
David Anson 2019-09-19 21:39:59 -07:00
parent 677255a484
commit 33e3797084
5 changed files with 32 additions and 28 deletions

View file

@ -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}`
}
);
}