mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Reimplement MD038/no-space-in-code to handle multi-backtick strings (fixes #46).
This commit is contained in:
parent
00171da565
commit
31206f9387
3 changed files with 51 additions and 13 deletions
25
lib/rules.js
25
lib/rules.js
|
|
@ -947,20 +947,19 @@ module.exports = [
|
|||
"aliases": [ "no-space-in-code" ],
|
||||
"regexp": spaceInsideCodeRe,
|
||||
"func": function MD038(params, errors) {
|
||||
var inlineCodeSpansRe = /(`+)((?:.*?[^`])|)\1(?!`)/g;
|
||||
forEachInlineChild(params, "code_inline",
|
||||
function forToken(token, inline) {
|
||||
var backtickPairs = "^(?:[^`]*`[^`]*`)*[^`]*";
|
||||
var escapedContent = escapeForRegExp(token.content);
|
||||
var left = (new RegExp(
|
||||
backtickPairs + "(`\\s+" + escapedContent + "\\s*`)"))
|
||||
.exec(inline.content);
|
||||
var right = (new RegExp(
|
||||
backtickPairs + "(`\\s*" + escapedContent + "\\s+`)"))
|
||||
.exec(inline.content);
|
||||
if (left) {
|
||||
errors.addContext(token.lineNumber, left[1]);
|
||||
} else if (right) {
|
||||
errors.addContext(token.lineNumber, right[1], false, true);
|
||||
function forToken(token) {
|
||||
var line = params.lines[token.lineNumber - 1];
|
||||
var match = null;
|
||||
while ((match = inlineCodeSpansRe.exec(line)) !== null) {
|
||||
var inlineCodeSpan = match[0];
|
||||
var content = match[2];
|
||||
if (/^\s([^`]|$)/.test(content)) {
|
||||
errors.addContext(token.lineNumber, inlineCodeSpan);
|
||||
} else if (/[^`]\s$/.test(content)) {
|
||||
errors.addContext(token.lineNumber, inlineCodeSpan, false, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue