mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD037/no-space-in-emphasis to ignore the content of HTML attributes (fixes #540).
This commit is contained in:
parent
48f47b5214
commit
1154ab483b
5 changed files with 209 additions and 39 deletions
43
lib/md037.js
43
lib/md037.js
|
@ -2,9 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorContext, emphasisMarkersInContent, forEachLine, isBlankLine } =
|
||||
require("../helpers");
|
||||
const { lineMetadata } = require("./cache");
|
||||
const { addErrorContext, emphasisMarkersInContent, forEachLine, isBlankLine,
|
||||
withinAnyRange } = require("../helpers");
|
||||
const { htmlElementRanges, lineMetadata } = require("./cache");
|
||||
|
||||
const emphasisRe = /(^|[^\\]|\\\\)(?:(\*\*?\*?)|(__?_?))/g;
|
||||
const embeddedUnderscoreRe = /([A-Za-z0-9])_([A-Za-z0-9])/g;
|
||||
|
@ -18,6 +18,7 @@ module.exports = {
|
|||
"description": "Spaces inside emphasis markers",
|
||||
"tags": [ "whitespace", "emphasis" ],
|
||||
"function": function MD037(params, onError) {
|
||||
const exclusions = htmlElementRanges();
|
||||
// eslint-disable-next-line init-declarations
|
||||
let effectiveEmphasisLength, emphasisIndex, emphasisKind, emphasisLength,
|
||||
pendingError = null;
|
||||
|
@ -50,25 +51,27 @@ module.exports = {
|
|||
// Report the violation
|
||||
const contextStart = emphasisIndex - emphasisLength;
|
||||
const contextEnd = matchIndex + contextLength;
|
||||
const context = line.substring(contextStart, contextEnd);
|
||||
const column = contextStart + 1;
|
||||
const length = contextEnd - contextStart;
|
||||
const leftMarker = line.substring(contextStart, emphasisIndex);
|
||||
const rightMarker = match ? (match[2] || match[3]) : "";
|
||||
const fixedText = `${leftMarker}${content.trim()}${rightMarker}`;
|
||||
return [
|
||||
onError,
|
||||
lineIndex + 1,
|
||||
context,
|
||||
leftSpace,
|
||||
rightSpace,
|
||||
[ column, length ],
|
||||
{
|
||||
"editColumn": column,
|
||||
"deleteCount": length,
|
||||
"insertText": fixedText
|
||||
}
|
||||
];
|
||||
if (!withinAnyRange(exclusions, lineIndex, column, length)) {
|
||||
const context = line.substring(contextStart, contextEnd);
|
||||
const leftMarker = line.substring(contextStart, emphasisIndex);
|
||||
const rightMarker = match ? (match[2] || match[3]) : "";
|
||||
const fixedText = `${leftMarker}${content.trim()}${rightMarker}`;
|
||||
return [
|
||||
onError,
|
||||
lineIndex + 1,
|
||||
context,
|
||||
leftSpace,
|
||||
rightSpace,
|
||||
[ column, length ],
|
||||
{
|
||||
"editColumn": column,
|
||||
"deleteCount": length,
|
||||
"insertText": fixedText
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue