Update MD037/no-space-in-emphasis to handle multiple embedded underscores separated by a single character (fixes #804).

This commit is contained in:
David Anson 2023-05-27 11:05:17 -07:00
parent dc4acff067
commit 8471914a1d
5 changed files with 17 additions and 4 deletions

View file

@ -5186,11 +5186,12 @@ var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"),
htmlElementRanges = _require2.htmlElementRanges,
lineMetadata = _require2.lineMetadata;
var emphasisRe = /(^|[^\\]|\\\\)(?:(\*{1,3})|(_{1,3}))/g;
var embeddedUnderscoreRe = /([A-Za-z\d])_([A-Za-z\d])/g;
var embeddedUnderscoreRe = /([A-Za-z\d])(_([A-Za-z\d]))+/g;
var asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/;
var leftSpaceRe = /^\s+/;
var rightSpaceRe = /\s+$/;
var tablePipeRe = /\|/;
var allUnderscoresRe = /_/g;
module.exports = {
"names": ["MD037", "no-space-in-emphasis"],
"description": "Spaces inside emphasis markers",
@ -5256,7 +5257,9 @@ module.exports = {
// Emphasis has no meaning here
return;
}
var patchedLine = line.replace(embeddedUnderscoreRe, "$1 $2");
var patchedLine = line.replace(embeddedUnderscoreRe, function (match) {
return match.replace(allUnderscoresRe, " ");
});
if (onItemStart) {
// Trim overlapping '*' list item marker
patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2");

View file

@ -7,11 +7,12 @@ const { addErrorContext, emphasisMarkersInContent, forEachLine, isBlankLine,
const { htmlElementRanges, lineMetadata } = require("./cache");
const emphasisRe = /(^|[^\\]|\\\\)(?:(\*{1,3})|(_{1,3}))/g;
const embeddedUnderscoreRe = /([A-Za-z\d])_([A-Za-z\d])/g;
const embeddedUnderscoreRe = /([A-Za-z\d])(_([A-Za-z\d]))+/g;
const asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/;
const leftSpaceRe = /^\s+/;
const rightSpaceRe = /\s+$/;
const tablePipeRe = /\|/;
const allUnderscoresRe = /_/g;
module.exports = {
"names": [ "MD037", "no-space-in-emphasis" ],
@ -102,7 +103,10 @@ module.exports = {
// Emphasis has no meaning here
return;
}
let patchedLine = line.replace(embeddedUnderscoreRe, "$1 $2");
let patchedLine = line.replace(
embeddedUnderscoreRe,
(match) => match.replace(allUnderscoresRe, " ")
);
if (onItemStart) {
// Trim overlapping '*' list item marker
patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2");

View file

@ -43625,6 +43625,9 @@ Generated by [AVA](https://avajs.dev).
Emphasis <img alt="inside * attribute * content"/> {MD033}␊
Emphasis <p data="* attribute *">*HTML*</p> {MD033} {MD037}␊
Embedded underscore is okay:␊
Text _emphas_i_s_ text _emphasis_
`,
}

View file

@ -369,3 +369,6 @@ Emphasis <p data="inside * attribute * content"></p> {MD033}
Emphasis <img alt="inside * attribute * content"/> {MD033}
Emphasis <p data="* attribute *">* HTML *</p> {MD033} {MD037}
Embedded underscore is okay:
Text _emphas_i_s_ text _emphasis_