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

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