mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-21 21:30:47 +02:00
Improve highlighting for MD037/no-space-in-emphasis, add more tests.
This commit is contained in:
parent
5fee0a921d
commit
4a27c3d100
3 changed files with 66 additions and 9 deletions
24
lib/rules.js
24
lib/rules.js
|
@ -15,7 +15,6 @@ var listItemMarkerInterruptsRe = /^[\s>]*(?:[*+-]|1\.)\s+/;
|
|||
var reversedLinkRe = /\([^)]+\)\[[^\]^][^\]]*]/;
|
||||
var spaceAfterBlockQuote = /^\s*(?:>\s+)+\S/;
|
||||
var spaceBeforeHeaderRe = /^\s+\S/;
|
||||
var spaceInsideEmphasisRe = /(\*\*?|__?)(?:(?:\s.+)|(?:.+\s))\1/;
|
||||
var spaceInsideLinkRe = /\[(?:(?:\s[^\]]*)|(?:[^\]]*\s))](?=\(\S*\))/;
|
||||
var tabRe = /\t+/;
|
||||
var trailingPunctuationRe = /.$/;
|
||||
|
@ -118,7 +117,7 @@ function forEachInlineChild(params, type, callback) {
|
|||
filterTokens(params, "inline", function forToken(token) {
|
||||
token.children.forEach(function forChild(child) {
|
||||
if (child.type === type) {
|
||||
callback(child, token);
|
||||
callback(child);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -962,15 +961,22 @@ module.exports = [
|
|||
"desc": "Spaces inside emphasis markers",
|
||||
"tags": [ "whitespace", "emphasis" ],
|
||||
"aliases": [ "no-space-in-emphasis" ],
|
||||
"regexp": spaceInsideEmphasisRe,
|
||||
"regexp": null,
|
||||
"func": function MD037(params, errors) {
|
||||
forEachInlineChild(params, "text", function forToken(token) {
|
||||
var left = /\s(\*\*?|__?)\s.+\1/.exec(token.content);
|
||||
var right = /(\*\*?|__?).+\s\1\s/.exec(token.content);
|
||||
if (left) {
|
||||
errors.addContext(token.lineNumber, left[0].trim());
|
||||
} else if (right) {
|
||||
errors.addContext(token.lineNumber, right[0].trim(), false, true);
|
||||
var left = true;
|
||||
var match = /\s(\*\*?|__?)\s.+\1/.exec(token.content);
|
||||
if (!match) {
|
||||
left = false;
|
||||
match = /(\*\*?|__?).+\s\1\s/.exec(token.content);
|
||||
}
|
||||
if (match) {
|
||||
var text = match[0].trim();
|
||||
var line = params.lines[token.lineNumber - 1];
|
||||
var column = line.indexOf(text) + 1;
|
||||
var length = text.length;
|
||||
errors.addContext(
|
||||
token.lineNumber, text, left, !left, [ column, length ]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue