docs: recommend highlighting with comments than number range (#6204)

* docs: recommend highlighting with comments than number range

* quick fix
This commit is contained in:
Joshua Chen 2021-12-28 10:55:24 +08:00 committed by GitHub
parent 73ee356949
commit 4f2330a824
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 74 deletions

View file

@ -45,9 +45,16 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
// Replace internal markdown linking (except in fenced blocks).
let fencedBlock = false;
let lastCodeFence = '';
const lines = fileString.split('\n').map((line) => {
if (line.trim().startsWith('```')) {
fencedBlock = !fencedBlock;
if (!fencedBlock) {
fencedBlock = true;
[lastCodeFence] = line.trim().match(/^`+/)!;
// If we are in a ````-fenced block, all ``` would be plain text instead of fences
} else if (line.trim().match(/^`+/)![0].length >= lastCodeFence.length) {
fencedBlock = false;
}
}
if (fencedBlock) {
return line;