mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Update MD037/no-space-in-emphasis to handle multiple embedded underscores separated by a single character (fixes #804).
This commit is contained in:
parent
dc4acff067
commit
8471914a1d
5 changed files with 17 additions and 4 deletions
|
|
@ -5186,11 +5186,12 @@ var _require2 = __webpack_require__(/*! ./cache */ "../lib/cache.js"),
|
||||||
htmlElementRanges = _require2.htmlElementRanges,
|
htmlElementRanges = _require2.htmlElementRanges,
|
||||||
lineMetadata = _require2.lineMetadata;
|
lineMetadata = _require2.lineMetadata;
|
||||||
var emphasisRe = /(^|[^\\]|\\\\)(?:(\*{1,3})|(_{1,3}))/g;
|
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 asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/;
|
||||||
var leftSpaceRe = /^\s+/;
|
var leftSpaceRe = /^\s+/;
|
||||||
var rightSpaceRe = /\s+$/;
|
var rightSpaceRe = /\s+$/;
|
||||||
var tablePipeRe = /\|/;
|
var tablePipeRe = /\|/;
|
||||||
|
var allUnderscoresRe = /_/g;
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": ["MD037", "no-space-in-emphasis"],
|
"names": ["MD037", "no-space-in-emphasis"],
|
||||||
"description": "Spaces inside emphasis markers",
|
"description": "Spaces inside emphasis markers",
|
||||||
|
|
@ -5256,7 +5257,9 @@ module.exports = {
|
||||||
// Emphasis has no meaning here
|
// Emphasis has no meaning here
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var patchedLine = line.replace(embeddedUnderscoreRe, "$1 $2");
|
var patchedLine = line.replace(embeddedUnderscoreRe, function (match) {
|
||||||
|
return match.replace(allUnderscoresRe, " ");
|
||||||
|
});
|
||||||
if (onItemStart) {
|
if (onItemStart) {
|
||||||
// Trim overlapping '*' list item marker
|
// Trim overlapping '*' list item marker
|
||||||
patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2");
|
patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2");
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,12 @@ const { addErrorContext, emphasisMarkersInContent, forEachLine, isBlankLine,
|
||||||
const { htmlElementRanges, lineMetadata } = require("./cache");
|
const { htmlElementRanges, lineMetadata } = require("./cache");
|
||||||
|
|
||||||
const emphasisRe = /(^|[^\\]|\\\\)(?:(\*{1,3})|(_{1,3}))/g;
|
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 asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/;
|
||||||
const leftSpaceRe = /^\s+/;
|
const leftSpaceRe = /^\s+/;
|
||||||
const rightSpaceRe = /\s+$/;
|
const rightSpaceRe = /\s+$/;
|
||||||
const tablePipeRe = /\|/;
|
const tablePipeRe = /\|/;
|
||||||
|
const allUnderscoresRe = /_/g;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"names": [ "MD037", "no-space-in-emphasis" ],
|
"names": [ "MD037", "no-space-in-emphasis" ],
|
||||||
|
|
@ -102,7 +103,10 @@ module.exports = {
|
||||||
// Emphasis has no meaning here
|
// Emphasis has no meaning here
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let patchedLine = line.replace(embeddedUnderscoreRe, "$1 $2");
|
let patchedLine = line.replace(
|
||||||
|
embeddedUnderscoreRe,
|
||||||
|
(match) => match.replace(allUnderscoresRe, " ")
|
||||||
|
);
|
||||||
if (onItemStart) {
|
if (onItemStart) {
|
||||||
// Trim overlapping '*' list item marker
|
// Trim overlapping '*' list item marker
|
||||||
patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2");
|
patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2");
|
||||||
|
|
|
||||||
|
|
@ -43625,6 +43625,9 @@ Generated by [AVA](https://avajs.dev).
|
||||||
Emphasis <img alt="inside * attribute * content"/> {MD033}␊
|
Emphasis <img alt="inside * attribute * content"/> {MD033}␊
|
||||||
␊
|
␊
|
||||||
Emphasis <p data="* attribute *">*HTML*</p> {MD033} {MD037}␊
|
Emphasis <p data="* attribute *">*HTML*</p> {MD033} {MD037}␊
|
||||||
|
␊
|
||||||
|
Embedded underscore is okay:␊
|
||||||
|
Text _emphas_i_s_ text _emphasis_␊
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -369,3 +369,6 @@ Emphasis <p data="inside * attribute * content"></p> {MD033}
|
||||||
Emphasis <img alt="inside * attribute * content"/> {MD033}
|
Emphasis <img alt="inside * attribute * content"/> {MD033}
|
||||||
|
|
||||||
Emphasis <p data="* attribute *">* HTML *</p> {MD033} {MD037}
|
Emphasis <p data="* attribute *">* HTML *</p> {MD033} {MD037}
|
||||||
|
|
||||||
|
Embedded underscore is okay:
|
||||||
|
Text _emphas_i_s_ text _emphasis_
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue