diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index 0fe2b1cb..d994a920 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -3211,6 +3211,7 @@ var emphasisRe = /(^|[^\\]|\\\\)(?:(\*\*?\*?)|(__?_?))/g; var asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/; var leftSpaceRe = /^\s+/; var rightSpaceRe = /\s+$/; +var tablePipeRe = /\|/; module.exports = { "names": ["MD037", "no-space-in-emphasis"], "description": "Spaces inside emphasis markers", @@ -3227,7 +3228,7 @@ module.exports = { pendingError = null; } // eslint-disable-next-line jsdoc/require-jsdoc - function handleRunEnd(line, lineIndex, contextLength, match, matchIndex) { + function handleRunEnd(line, lineIndex, contextLength, match, matchIndex, inTable) { // Close current run var content = line.substring(emphasisIndex, matchIndex); if (!emphasisLength) { @@ -3238,7 +3239,8 @@ module.exports = { } var leftSpace = leftSpaceRe.test(content); var rightSpace = rightSpaceRe.test(content); - if (leftSpace || rightSpace) { + if ((leftSpace || rightSpace) && + (!inTable || !tablePipeRe.test(content))) { // Report the violation var contextStart = emphasisIndex - emphasisLength; var contextEnd = matchIndex + contextLength; @@ -3308,7 +3310,7 @@ module.exports = { addErrorContext.apply(void 0, pendingError); pendingError = null; } - var error = handleRunEnd(line, lineIndex, effectiveEmphasisLength, match, matchIndex); + var error = handleRunEnd(line, lineIndex, effectiveEmphasisLength, match, matchIndex, inTable); if (error) { // @ts-ignore addErrorContext.apply(void 0, error); @@ -3342,7 +3344,7 @@ module.exports = { } if (emphasisIndex !== -1) { pendingError = pendingError || - handleRunEnd(line, lineIndex, 0, null, line.length); + handleRunEnd(line, lineIndex, 0, null, line.length, inTable); // Adjust for pending run on new line emphasisIndex = 0; emphasisLength = 0; diff --git a/lib/md037.js b/lib/md037.js index 850639ab..34a4d0e0 100644 --- a/lib/md037.js +++ b/lib/md037.js @@ -10,6 +10,7 @@ const emphasisRe = /(^|[^\\]|\\\\)(?:(\*\*?\*?)|(__?_?))/g; const asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/; const leftSpaceRe = /^\s+/; const rightSpaceRe = /\s+$/; +const tablePipeRe = /\|/; module.exports = { "names": [ "MD037", "no-space-in-emphasis" ], @@ -28,7 +29,9 @@ module.exports = { pendingError = null; } // eslint-disable-next-line jsdoc/require-jsdoc - function handleRunEnd(line, lineIndex, contextLength, match, matchIndex) { + function handleRunEnd( + line, lineIndex, contextLength, match, matchIndex, inTable + ) { // Close current run let content = line.substring(emphasisIndex, matchIndex); if (!emphasisLength) { @@ -39,7 +42,10 @@ module.exports = { } const leftSpace = leftSpaceRe.test(content); const rightSpace = rightSpaceRe.test(content); - if (leftSpace || rightSpace) { + if ( + (leftSpace || rightSpace) && + (!inTable || !tablePipeRe.test(content)) + ) { // Report the violation const contextStart = emphasisIndex - emphasisLength; const contextEnd = matchIndex + contextLength; @@ -111,7 +117,13 @@ module.exports = { pendingError = null; } const error = handleRunEnd( - line, lineIndex, effectiveEmphasisLength, match, matchIndex); + line, + lineIndex, + effectiveEmphasisLength, + match, + matchIndex, + inTable + ); if (error) { // @ts-ignore addErrorContext(...error); @@ -141,7 +153,7 @@ module.exports = { } if (emphasisIndex !== -1) { pendingError = pendingError || - handleRunEnd(line, lineIndex, 0, null, line.length); + handleRunEnd(line, lineIndex, 0, null, line.length, inTable); // Adjust for pending run on new line emphasisIndex = 0; emphasisLength = 0; diff --git a/test/spaces_inside_emphasis_markers.md b/test/spaces_inside_emphasis_markers.md index 8998ec62..237c15ad 100644 --- a/test/spaces_inside_emphasis_markers.md +++ b/test/spaces_inside_emphasis_markers.md @@ -313,3 +313,31 @@ text [reference*link] star * star text *** text **text** *** + +| Table | Table | +| ----- | ----- | +| star | x * y | +| under | x _ y | + +| Table | Table | +| ----- | ----- | +| star | x * y | +| star | x * y | +| under | x _ y | +| under | x _ y | + +| Table | Table | +| ----- | ------------------------- | +| star | text *text* text | +| star | text * text* text {MD037} | +| star | text *text * text {MD037} | +| under | text _text_ text | +| under | text _ text_ text {MD037} | +| under | text _text _ text {MD037} | + +| Table | Table | +| ----- | ----- | +| x * y | x * y | +| x** y | x** y | +| x _ y | x _ y | +| x__ y | x__ y |