mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD037/no-space-in-emphasis to handle more scenarios (refs #286).
This commit is contained in:
parent
37f1d6b64b
commit
f607a49a5b
3 changed files with 101 additions and 28 deletions
57
lib/md037.js
57
lib/md037.js
|
|
@ -6,8 +6,8 @@ const { addErrorContext, emphasisMarkersInContent, forEachLine, isBlankLine } =
|
|||
require("../helpers");
|
||||
const { lineMetadata } = require("./cache");
|
||||
|
||||
const emphasisRe = /(^|[^\\])(?:(\*\*?\*?)|(__?_?))/g;
|
||||
const asteriskListItemMarkerRe = /^(\s*)\*(\s+)/;
|
||||
const emphasisRe = /(^|[^\\]|\\\\)(?:(\*\*?\*?)|(__?_?))/g;
|
||||
const asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/;
|
||||
const leftSpaceRe = /^\s+/;
|
||||
const rightSpaceRe = /\s+$/;
|
||||
|
||||
|
|
@ -101,31 +101,38 @@ module.exports = {
|
|||
emphasisLength = matchLength;
|
||||
emphasisKind = matchKind;
|
||||
effectiveEmphasisLength = matchLength;
|
||||
} else if (
|
||||
(matchLength === effectiveEmphasisLength) &&
|
||||
(matchKind === emphasisKind)
|
||||
) {
|
||||
// Ending an existing run, report any pending error
|
||||
if (pendingError) {
|
||||
addErrorContext(...pendingError);
|
||||
pendingError = null;
|
||||
} else if (matchKind === emphasisKind) {
|
||||
// Matching emphasis markers
|
||||
if (matchLength === effectiveEmphasisLength) {
|
||||
// Ending an existing run, report any pending error
|
||||
if (pendingError) {
|
||||
addErrorContext(...pendingError);
|
||||
pendingError = null;
|
||||
}
|
||||
const error = handleRunEnd(
|
||||
line, lineIndex, effectiveEmphasisLength, match, matchIndex);
|
||||
if (error) {
|
||||
addErrorContext(...error);
|
||||
}
|
||||
// Reset
|
||||
resetRunTracking();
|
||||
} else if (matchLength === 3) {
|
||||
// Swap internal run length (1->2 or 2->1)
|
||||
effectiveEmphasisLength = matchLength - effectiveEmphasisLength;
|
||||
} else if (effectiveEmphasisLength === 3) {
|
||||
// Downgrade internal run (3->1 or 3->2)
|
||||
effectiveEmphasisLength -= matchLength;
|
||||
} else {
|
||||
// Upgrade to internal run (1->3 or 2->3)
|
||||
effectiveEmphasisLength += matchLength;
|
||||
}
|
||||
const error = handleRunEnd(
|
||||
line, lineIndex, effectiveEmphasisLength, match, matchIndex);
|
||||
if (error) {
|
||||
addErrorContext(...error);
|
||||
}
|
||||
// Reset
|
||||
resetRunTracking();
|
||||
} else if (matchLength === 3) {
|
||||
// Swap internal run length (1->2 or 2->1)
|
||||
effectiveEmphasisLength = matchLength - effectiveEmphasisLength;
|
||||
} else if (effectiveEmphasisLength === 3) {
|
||||
// Downgrade internal run (3->1 or 3->2)
|
||||
effectiveEmphasisLength -= matchLength;
|
||||
// Back up one character so RegExp has a chance to match the
|
||||
// next marker (ex: "**star**_underscore_")
|
||||
emphasisRe.lastIndex--;
|
||||
} else {
|
||||
// Upgrade to internal run (1->3 or 2->3)
|
||||
effectiveEmphasisLength += matchLength;
|
||||
// Back up one character so RegExp has a chance to match the
|
||||
// mis-matched marker (ex: "*text_*")
|
||||
emphasisRe.lastIndex--;
|
||||
}
|
||||
}
|
||||
if (emphasisIndex !== -1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue