Update MD038/no-space-in-code to ignore backticks in link destinations (fixes #206).

This commit is contained in:
David Anson 2019-07-28 16:48:32 -07:00
parent cd7a65cedd
commit c3e8eab87b
3 changed files with 46 additions and 2 deletions

View file

@ -12,6 +12,7 @@
"array-bracket-spacing": ["error", "always"],
"array-element-newline": "off",
"capitalized-comments": "off",
"complexity": "off",
"dot-location": ["error", "property"],
"func-style": ["error", "declaration"],
"function-paren-newline": "off",
@ -22,7 +23,7 @@
"max-lines": "off",
"max-lines-per-function": "off",
"max-params": ["error", 10],
"max-statements": ["error", 33],
"max-statements": "off",
"multiline-comment-style": ["error", "separate-lines"],
"multiline-ternary": "off",
"newline-per-chained-call": "off",

View file

@ -259,10 +259,25 @@ module.exports.forEachInlineCodeSpan =
let startColumn = -1;
let tickCount = 0;
let currentTicks = 0;
let state = "normal";
// Deliberate <= so trailing 0 completes the last span (ex: "text `code`")
for (; index <= input.length; index++) {
const char = input[index];
if (char === "`") {
// Ignore backticks in link destination
if ((char === "[") && (state === "normal")) {
state = "linkTextOpen";
} else if ((char === "]") && (state === "linkTextOpen")) {
state = "linkTextClosed";
} else if ((char === "(") && (state === "linkTextClosed")) {
state = "linkDestinationOpen";
} else if (
((char === "(") && (state === "linkDestinationOpen")) ||
((char === ")") && (state === "linkDestinationOpen")) ||
(state === "linkTextClosed")) {
state = "normal";
}
// Parse backtick open/close
if ((char === "`") && (state !== "linkDestinationOpen")) {
// Count backticks at start or end of code span
currentTicks++;
if ((startIndex === -1) || (startColumn === -1)) {

View file

@ -67,3 +67,31 @@ text and ``\`code with ignored escaped \` backticks``
``multiple trailing spaces not allowed ` `` text `code` {MD038}
`` ` leading and trailing space allowed for backtick ` `` text `code`
Text [link](https://example.com/link`link) text `code`.
Text [link](https://example.com/link```link) text ```code```.
Text [link](https://example.com/link`link`link`link) text `code`.
Text [link](https://example.com/link "title`title") text `code`.
Text [link](#link`link) text `code`.
Text [link] (#link`link) text `code`. {MD038}
Text [link[link](#link`link) text `code`.
Text [link(link](#link`link) text `code`.
Text [link)link](#link`link) text `code`.
Text [link](#link[link`link) text `code`.
Text [link](#link]link`link) text `code`.
Text [link](#link(link`link) text `code`. {MD038}
Text [`link`](xref:custom.link`1) text `code`.
Text ``code [link](#link`link) code`` text `code`.