mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD038/no-space-in-code to ignore backticks in link destinations (fixes #206).
This commit is contained in:
parent
cd7a65cedd
commit
c3e8eab87b
3 changed files with 46 additions and 2 deletions
|
@ -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",
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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`.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue