Update MD051/link-fragments to support GitHub-style line/column range syntax in URLs (refs #1117).

This commit is contained in:
Théo LUDWIG 2024-02-07 20:45:56 +01:00 committed by David Anson
parent ece0ccf269
commit 242b35f98f
8 changed files with 329 additions and 26 deletions

View file

@ -5470,7 +5470,9 @@ module.exports = {
startColumn
} = definition;
const text = unescapeStringTokenText(definition);
if (text.length > 1 && text.startsWith("#") && !fragments.has(text) && !fragments.has(`#${encodeURIComponent(text.slice(1))}`)) {
const encodedText = `#${encodeURIComponent(text.slice(1))}`;
const lineFragmentRe = /^#L\d+(?:C\d+)?(?:-L\d+(?:C\d+)?)?$/;
if (text.length > 1 && text.startsWith("#") && !fragments.has(encodedText) && !lineFragmentRe.test(encodedText)) {
// eslint-disable-next-line no-undef-init
let context = undefined;
// eslint-disable-next-line no-undef-init