mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 08:37:25 +02:00
fix(utils): recognize ~~~ as code fences in link replacement (#7801)
This commit is contained in:
parent
fe3dfa720a
commit
1dd65eee50
3 changed files with 31 additions and 9 deletions
|
@ -76,6 +76,18 @@ exports[`replaceMarkdownLinks ignores links in fenced blocks 1`] = `
|
||||||
\`\`\`
|
\`\`\`
|
||||||
[foo](foo.md)
|
[foo](foo.md)
|
||||||
\`\`\`\`
|
\`\`\`\`
|
||||||
|
|
||||||
|
~~~js
|
||||||
|
[foo](foo.md)
|
||||||
|
~~~
|
||||||
|
|
||||||
|
~~~js
|
||||||
|
[foo](foo.md)
|
||||||
|
\`\`\`
|
||||||
|
[foo](foo.md)
|
||||||
|
\`\`\`
|
||||||
|
[foo](foo.md)
|
||||||
|
~~~
|
||||||
",
|
",
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
|
@ -179,6 +179,18 @@ The following operations are defined for [URI]s:
|
||||||
\`\`\`
|
\`\`\`
|
||||||
[foo](foo.md)
|
[foo](foo.md)
|
||||||
\`\`\`\`
|
\`\`\`\`
|
||||||
|
|
||||||
|
~~~js
|
||||||
|
[foo](foo.md)
|
||||||
|
~~~
|
||||||
|
|
||||||
|
~~~js
|
||||||
|
[foo](foo.md)
|
||||||
|
\`\`\`
|
||||||
|
[foo](foo.md)
|
||||||
|
\`\`\`
|
||||||
|
[foo](foo.md)
|
||||||
|
~~~
|
||||||
`,
|
`,
|
||||||
}),
|
}),
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
|
|
|
@ -82,21 +82,19 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
|
||||||
const brokenMarkdownLinks: BrokenMarkdownLink<T>[] = [];
|
const brokenMarkdownLinks: BrokenMarkdownLink<T>[] = [];
|
||||||
|
|
||||||
// Replace internal markdown linking (except in fenced blocks).
|
// Replace internal markdown linking (except in fenced blocks).
|
||||||
let fencedBlock = false;
|
let lastCodeFence: string | null = null;
|
||||||
let lastCodeFence = '';
|
|
||||||
const lines = fileString.split('\n').map((line) => {
|
const lines = fileString.split('\n').map((line) => {
|
||||||
if (line.trim().startsWith('```')) {
|
const codeFence = line.trimStart().match(/^`{3,}|^~{3,}/)?.[0];
|
||||||
const codeFence = line.trim().match(/^`+/)![0]!;
|
if (codeFence) {
|
||||||
if (!fencedBlock) {
|
if (!lastCodeFence) {
|
||||||
fencedBlock = true;
|
|
||||||
lastCodeFence = codeFence;
|
lastCodeFence = codeFence;
|
||||||
// If we are in a ````-fenced block, all ``` would be plain text instead
|
// If we are in a ````-fenced block, all ``` would be plain text instead
|
||||||
// of fences
|
// of fences
|
||||||
} else if (codeFence.length >= lastCodeFence.length) {
|
} else if (codeFence.startsWith(lastCodeFence)) {
|
||||||
fencedBlock = false;
|
lastCodeFence = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fencedBlock) {
|
if (lastCodeFence) {
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue