mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD037/no-space-in-emphasis to ignore emphasis markers in code spans (fixes #278).
This commit is contained in:
parent
bdc0246b34
commit
f5a71521d4
5 changed files with 195 additions and 76 deletions
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorContext, forEachLine, isBlankLine } = require("../helpers");
|
||||
const { addErrorContext, emphasisMarkersInCodeSpans, forEachLine,
|
||||
includesSorted, isBlankLine } = require("../helpers");
|
||||
const { lineMetadata } = require("./cache");
|
||||
|
||||
const emphasisRe = /(^|[^\\])(?:(\*\*?\*?)|(__?_?))/g;
|
||||
|
|
@ -63,6 +64,7 @@ module.exports = {
|
|||
return null;
|
||||
}
|
||||
// Initialize
|
||||
const ignoreMarkersByLine = emphasisMarkersInCodeSpans(params);
|
||||
resetRunTracking();
|
||||
forEachLine(
|
||||
lineMetadata(),
|
||||
|
|
@ -83,7 +85,12 @@ module.exports = {
|
|||
let match = null;
|
||||
// Match all emphasis-looking runs in the line...
|
||||
while ((match = emphasisRe.exec(line))) {
|
||||
const ignoreMarkersForLine = ignoreMarkersByLine[lineIndex] || [];
|
||||
const matchIndex = match.index + match[1].length;
|
||||
if (includesSorted(ignoreMarkersForLine, matchIndex)) {
|
||||
// Ignore emphasis markers inside code spans
|
||||
continue;
|
||||
}
|
||||
const matchLength = match[0].length - match[1].length;
|
||||
if (emphasisIndex === -1) {
|
||||
// New run
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue