mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD053/link-image-reference-definitions to handle references within references (i.e., Pandoc-style footnotes), verify Pandoc footnote indent is not treated as comment when markdown-it-footnote plugin is used (fixes #599).
This commit is contained in:
parent
7d1fa55cc4
commit
592a42b0cb
8 changed files with 169 additions and 2 deletions
|
@ -802,7 +802,8 @@ function getReferenceLinkImageData(lineMetadata) {
|
|||
else {
|
||||
definitions.set(label, lineIndex);
|
||||
}
|
||||
exclusions.push([0, lineOffsets[lineIndex], line.length]);
|
||||
const labelLength = linkReferenceDefinitionMatch[0].length;
|
||||
exclusions.push([0, lineOffsets[lineIndex], labelLength]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -836,7 +836,8 @@ function getReferenceLinkImageData(lineMetadata) {
|
|||
} else {
|
||||
definitions.set(label, lineIndex);
|
||||
}
|
||||
exclusions.push([ 0, lineOffsets[lineIndex], line.length ]);
|
||||
const labelLength = linkReferenceDefinitionMatch[0].length;
|
||||
exclusions.push([ 0, lineOffsets[lineIndex], labelLength ]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -69,6 +69,7 @@
|
|||
"eslint-plugin-unicorn": "44.0.2",
|
||||
"globby": "13.1.2",
|
||||
"js-yaml": "4.1.0",
|
||||
"markdown-it-footnote": "3.0.3",
|
||||
"markdown-it-for-inline": "0.1.1",
|
||||
"markdown-it-sub": "1.0.0",
|
||||
"markdown-it-sup": "1.0.0",
|
||||
|
|
|
@ -6,6 +6,7 @@ const fs = require("node:fs");
|
|||
const path = require("node:path");
|
||||
const jsYaml = require("js-yaml");
|
||||
const md = require("markdown-it")();
|
||||
const pluginFootnote = require("markdown-it-footnote");
|
||||
const pluginInline = require("markdown-it-for-inline");
|
||||
const pluginSub = require("markdown-it-sub");
|
||||
const pluginSup = require("markdown-it-sup");
|
||||
|
@ -1254,6 +1255,32 @@ test("texmath test files with texmath plugin", (t) => new Promise((resolve) => {
|
|||
});
|
||||
}));
|
||||
|
||||
test("Pandoc footnote via footnote plugin", (t) => new Promise((resolve) => {
|
||||
t.plan(2);
|
||||
markdownlint({
|
||||
"strings": {
|
||||
"string":
|
||||
`# Heading
|
||||
|
||||
Text with: [^footnote]
|
||||
|
||||
[^footnote]: Footnote text on multiple
|
||||
|
||||
lines including a [reference][]
|
||||
|
||||
[reference]: https://example.com
|
||||
`
|
||||
},
|
||||
"markdownItPlugins": [ [ pluginFootnote ] ],
|
||||
"resultVersion": 0
|
||||
}, (err, actual) => {
|
||||
t.falsy(err);
|
||||
const expected = { "string": {} };
|
||||
t.deepEqual(actual, expected, "Unexpected issues.");
|
||||
resolve();
|
||||
});
|
||||
}));
|
||||
|
||||
test("token-map-spans", (t) => {
|
||||
t.plan(38);
|
||||
const options = {
|
||||
|
|
47
test/pandoc-footnotes.md
Normal file
47
test/pandoc-footnotes.md
Normal file
|
@ -0,0 +1,47 @@
|
|||
# Pandoc Footnotes
|
||||
|
||||
> Examples taken from [GitHub issue 599](https://github.com/DavidAnson/markdownlint/issues/599)
|
||||
|
||||
## Example with Pandoc Footnotes
|
||||
|
||||
A sentence with footnotes: [^1] [^2]
|
||||
A sentence with named footnotes: [^name] [^name2]
|
||||
A sentence with a link reference: [Pandoc's User Guide][Pandoc1]
|
||||
|
||||
[^1]: I am a footnote!
|
||||
[^2]: I reference a [PCW][PCW1] article!
|
||||
[^name]: I am a footnote with name!
|
||||
[^name2]: I am also a named footnote! I also reference the [PCW][PCW1] article!
|
||||
|
||||
[PCW1]: https://www.example.com/article.html
|
||||
[Pandoc1]: https://pandoc.org/MANUAL.html#extension-footnotes
|
||||
|
||||
## Example with Long Pandoc Footnotes
|
||||
|
||||
A sentence with a long footnotes: [^long] [^longer] [^longest]
|
||||
|
||||
[^long]: I am a long footnote!
|
||||
I don't do any harm :)
|
||||
[^longer]: I am a longer footnote. I do reference the [PCW][PCW2] article.
|
||||
I do harm. Though, not here: [Pandoc's User Guide][Pandoc2]
|
||||
[^longest]: I am the longest footnote. I also reference the [PCW][PCW2] article.
|
||||
|
||||
I am a harmful new block of text: [Another][Another2]
|
||||
|
||||
> The previous line of text is treated by CommonMark as an indented code block.
|
||||
> To handle it as a Pandoc footnote, consider the `markdown-it-footnote` plugin.
|
||||
|
||||
[PCW2]: https://www.example.com/article.html
|
||||
[Pandoc2]: https://pandoc.org/MANUAL.html#extension-footnotes
|
||||
[Another2]: https://www.example.com/another.{MD053}.html
|
||||
|
||||
## GitHub Footnotes
|
||||
|
||||
Sample footnotes [^3] [^note3]
|
||||
|
||||
[^3]: A line
|
||||
A new line
|
||||
|
||||
[^note3]:
|
||||
I am a new block of text
|
||||
With a new line as well
|
|
@ -228,3 +228,11 @@ Not flagged due to ambiguity: [ignored]
|
|||
Unmatched [ in text
|
||||
|
||||
Hidden reference: [hidden][] {MD052}
|
||||
|
||||
## Link references inside reference definitions
|
||||
|
||||
Text with a [^footnote] in it
|
||||
|
||||
[^footnote]: Footnote with an [embedded-reference][] in it
|
||||
|
||||
[embedded-reference]: https://example.com/embedded-reference
|
||||
|
|
|
@ -32084,6 +32084,80 @@ Generated by [AVA](https://avajs.dev).
|
|||
`,
|
||||
}
|
||||
|
||||
## pandoc-footnotes.md
|
||||
|
||||
> Snapshot 1
|
||||
|
||||
{
|
||||
errors: [
|
||||
{
|
||||
errorContext: '[Another2]: https://www.exampl...',
|
||||
errorDetail: 'Unused link or image reference definition: "another2"',
|
||||
errorRange: [
|
||||
1,
|
||||
56,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: -1,
|
||||
},
|
||||
lineNumber: 36,
|
||||
ruleDescription: 'Link and image reference definitions should be needed',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md053',
|
||||
ruleNames: [
|
||||
'MD053',
|
||||
'link-image-reference-definitions',
|
||||
],
|
||||
},
|
||||
],
|
||||
fixed: `# Pandoc Footnotes␊
|
||||
␊
|
||||
> Examples taken from [GitHub issue 599](https://github.com/DavidAnson/markdownlint/issues/599)␊
|
||||
␊
|
||||
## Example with Pandoc Footnotes␊
|
||||
␊
|
||||
A sentence with footnotes: [^1] [^2]␊
|
||||
A sentence with named footnotes: [^name] [^name2]␊
|
||||
A sentence with a link reference: [Pandoc's User Guide][Pandoc1]␊
|
||||
␊
|
||||
[^1]: I am a footnote!␊
|
||||
[^2]: I reference a [PCW][PCW1] article!␊
|
||||
[^name]: I am a footnote with name!␊
|
||||
[^name2]: I am also a named footnote! I also reference the [PCW][PCW1] article!␊
|
||||
␊
|
||||
[PCW1]: https://www.example.com/article.html␊
|
||||
[Pandoc1]: https://pandoc.org/MANUAL.html#extension-footnotes␊
|
||||
␊
|
||||
## Example with Long Pandoc Footnotes␊
|
||||
␊
|
||||
A sentence with a long footnotes: [^long] [^longer] [^longest]␊
|
||||
␊
|
||||
[^long]: I am a long footnote!␊
|
||||
I don't do any harm :)␊
|
||||
[^longer]: I am a longer footnote. I do reference the [PCW][PCW2] article.␊
|
||||
I do harm. Though, not here: [Pandoc's User Guide][Pandoc2]␊
|
||||
[^longest]: I am the longest footnote. I also reference the [PCW][PCW2] article.␊
|
||||
␊
|
||||
I am a harmful new block of text: [Another][Another2]␊
|
||||
␊
|
||||
> The previous line of text is treated by CommonMark as an indented code block.␊
|
||||
> To handle it as a Pandoc footnote, consider the \`markdown-it-footnote\` plugin.␊
|
||||
␊
|
||||
[PCW2]: https://www.example.com/article.html␊
|
||||
[Pandoc2]: https://pandoc.org/MANUAL.html#extension-footnotes␊
|
||||
␊
|
||||
## GitHub Footnotes␊
|
||||
␊
|
||||
Sample footnotes [^3] [^note3]␊
|
||||
␊
|
||||
[^3]: A line␊
|
||||
A new line␊
|
||||
␊
|
||||
[^note3]:␊
|
||||
I am a new block of text␊
|
||||
With a new line as well␊
|
||||
`,
|
||||
}
|
||||
|
||||
## proper-names-alternate.md
|
||||
|
||||
> Snapshot 1
|
||||
|
@ -34592,6 +34666,14 @@ Generated by [AVA](https://avajs.dev).
|
|||
Unmatched [ in text␊
|
||||
␊
|
||||
Hidden reference: [hidden][] {MD052}␊
|
||||
␊
|
||||
## Link references inside reference definitions␊
|
||||
␊
|
||||
Text with a [^footnote] in it␊
|
||||
␊
|
||||
[^footnote]: Footnote with an [embedded-reference][] in it␊
|
||||
␊
|
||||
[embedded-reference]: https://example.com/embedded-reference␊
|
||||
`,
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue