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 violations in tables that include the table pipe character to avoid spanning cells.
This commit is contained in:
parent
238781506a
commit
d6cd840e7d
3 changed files with 50 additions and 8 deletions
20
lib/md037.js
20
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue