Skip to content

fix(selectors): skip id partial matching on headed level sections - #495

Open
EnesKartal wants to merge 1 commit into
kepano:mainfrom
EnesKartal:fix/section-heading-slug-ids-468
Open

EnesKartal wants to merge 1 commit into
kepano:mainfrom
EnesKartal:fix/section-heading-slug-ids-468

Conversation

@EnesKartal

Copy link
Copy Markdown
Contributor

Fixes #468

Root cause

isLevelSectionHeadingId in src/removals/selectors.ts previously compared <section class="levelN"> IDs against a naive hyphen-normalized slug of the heading text (replace(/[^\p{L}\p{N}]+/gu, '-')). That still dropped Pandoc/Quarto content sections whose id contained a partial-selector word (favorite, recommend, relevant, -error) whenever:

  • Pandoc stripped punctuation like apostrophes or slashes instead of replacing them with hyphens (e.g. What's -> whats, pass/fail -> passfail), or
  • the author edited the heading text while preserving an explicit {#custom-id} anchor for backwards-compatible URLs.

Fix

In Pandoc/Quarto --section-divs output, <section class="levelN"> hoists the heading anchor ID onto the section wrapper. Skip id partial matching on <section class="levelN"> whenever it has a sec- prefix or contains a heading (h1-h6), matching how Defuddle already skips id on heading elements. Non-level clutter sections (e.g. #related-posts), unheaded levelN sections, and levelN sections with clutter class names are still removed.

Verification

  • Verified against https://hamel.dev/blog/posts/evals-faq/: all 5 previously dropped FAQ sections are now preserved (0 non-chrome partial removals).
  • Added unit tests in tests/table-and-section-selectors.test.ts (both linkedom and jsdom).
  • npx vitest run tests/table-and-section-selectors.test.ts tests/class-selectors.test.ts: 78/78 passed.
  • npx tsc --noEmit, npm run build:types, npm run build:node: passed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clutter removal removes content sections whose id contains a partial-selector word (for example "error-")

1 participant