Update MD037/no-space-in-emphasis to avoid pairing different kinds of emphasis marker.

This commit is contained in:
David Anson 2020-04-25 15:30:52 -07:00
parent f5a71521d4
commit 70dc8fb6d3
2 changed files with 26 additions and 2 deletions

View file

@ -17,11 +17,13 @@ module.exports = {
"tags": [ "whitespace", "emphasis" ],
"function": function MD037(params, onError) {
// eslint-disable-next-line init-declarations
let effectiveEmphasisLength, emphasisIndex, emphasisLength, pendingError;
let effectiveEmphasisLength, emphasisIndex, emphasisKind, emphasisLength,
pendingError = null;
// eslint-disable-next-line jsdoc/require-jsdoc
function resetRunTracking() {
emphasisIndex = -1;
emphasisLength = 0;
emphasisKind = "";
effectiveEmphasisLength = 0;
pendingError = null;
}
@ -92,12 +94,17 @@ module.exports = {
continue;
}
const matchLength = match[0].length - match[1].length;
const matchKind = (match[2] || match[3])[0];
if (emphasisIndex === -1) {
// New run
emphasisIndex = matchIndex + matchLength;
emphasisLength = matchLength;
emphasisKind = matchKind;
effectiveEmphasisLength = matchLength;
} else if (matchLength === effectiveEmphasisLength) {
} else if (
(matchLength === effectiveEmphasisLength) &&
(matchKind === emphasisKind)
) {
// Ending an existing run, report any pending error
if (pendingError) {
addErrorContext(...pendingError);

View file

@ -0,0 +1,17 @@
# Mixed Emphasis Markers
This paragraph *uses* both _kinds_ of emphasis marker.
This paragraph _uses_ both *kinds* of emphasis marker.
This paragraph *nests both _kinds_ of emphasis* marker.
This paragraph *nests both __kinds__ of emphasis* marker.
This paragraph **nests both __kinds__ of emphasis** marker.
This paragraph _nests both *kinds* of emphasis_ marker.
This paragraph _nests both **kinds** of emphasis_ marker.
This paragraph __nests both **kinds** of emphasis__ marker.