mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD037/no-space-in-emphasis to avoid pairing different kinds of emphasis marker.
This commit is contained in:
parent
f5a71521d4
commit
70dc8fb6d3
2 changed files with 26 additions and 2 deletions
11
lib/md037.js
11
lib/md037.js
|
@ -17,11 +17,13 @@ module.exports = {
|
||||||
"tags": [ "whitespace", "emphasis" ],
|
"tags": [ "whitespace", "emphasis" ],
|
||||||
"function": function MD037(params, onError) {
|
"function": function MD037(params, onError) {
|
||||||
// eslint-disable-next-line init-declarations
|
// 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
|
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||||
function resetRunTracking() {
|
function resetRunTracking() {
|
||||||
emphasisIndex = -1;
|
emphasisIndex = -1;
|
||||||
emphasisLength = 0;
|
emphasisLength = 0;
|
||||||
|
emphasisKind = "";
|
||||||
effectiveEmphasisLength = 0;
|
effectiveEmphasisLength = 0;
|
||||||
pendingError = null;
|
pendingError = null;
|
||||||
}
|
}
|
||||||
|
@ -92,12 +94,17 @@ module.exports = {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const matchLength = match[0].length - match[1].length;
|
const matchLength = match[0].length - match[1].length;
|
||||||
|
const matchKind = (match[2] || match[3])[0];
|
||||||
if (emphasisIndex === -1) {
|
if (emphasisIndex === -1) {
|
||||||
// New run
|
// New run
|
||||||
emphasisIndex = matchIndex + matchLength;
|
emphasisIndex = matchIndex + matchLength;
|
||||||
emphasisLength = matchLength;
|
emphasisLength = matchLength;
|
||||||
|
emphasisKind = matchKind;
|
||||||
effectiveEmphasisLength = matchLength;
|
effectiveEmphasisLength = matchLength;
|
||||||
} else if (matchLength === effectiveEmphasisLength) {
|
} else if (
|
||||||
|
(matchLength === effectiveEmphasisLength) &&
|
||||||
|
(matchKind === emphasisKind)
|
||||||
|
) {
|
||||||
// Ending an existing run, report any pending error
|
// Ending an existing run, report any pending error
|
||||||
if (pendingError) {
|
if (pendingError) {
|
||||||
addErrorContext(...pendingError);
|
addErrorContext(...pendingError);
|
||||||
|
|
17
test/mixed-emphasis-markers.md
Normal file
17
test/mixed-emphasis-markers.md
Normal 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.
|
Loading…
Add table
Add a link
Reference in a new issue