Refine previous commit for MD051/link-fragments to tweak behavior, tests, and documentation.

This commit is contained in:
David Anson 2024-02-10 15:36:12 -08:00
parent 242b35f98f
commit 45c8766eda
8 changed files with 259 additions and 148 deletions

View file

@ -5383,6 +5383,7 @@ const {
const idRe = getHtmlAttributeRe("id");
const nameRe = getHtmlAttributeRe("name");
const anchorRe = /\{(#[a-z\d]+(?:[-_][a-z\d]+)*)\}/gu;
const lineFragmentRe = /^#(?:L\d+(?:C\d+)?-L\d+(?:C\d+)?|L\d+)$/;
// Sets for filtering heading tokens during conversion
const childrenExclude = new Set(["image", "reference", "resource"]);
@ -5471,7 +5472,6 @@ module.exports = {
} = 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(encodedText) && !lineFragmentRe.test(encodedText)) {
// eslint-disable-next-line no-undef-init
let context = undefined;