0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Adds clickable anchor links to headings with auto-generated IDs and click-to-copy URL support.
Overview
Wraps a content area and adds a permalink anchor to each heading. Hover or focus a heading to reveal the link icon (on touch devices it is always shown); activating it jumps to the section, updates the URL hash, and copies the section URL to the clipboard.
Usage
Wrap any content containing headings. By default, h2 and h3 elements are processed.
Which heading levels to process. Other tokens are ignored (an all-invalid value falls back to the default). Changes are observed: headings that drop out of scope lose their anchor.
data-label-anchor
Text
Copy link to
Prefix of each anchor's accessible name; the anchor is named prefix + heading text. Localise here.
data-label-copied
Text
Link copied to clipboard
Screen-reader announcement after a copy
data-toc-ignore
Boolean, on a heading or ancestor
—
Skip the heading(s): no anchor, no generated ID. Shared with <page-toc>.
Custom heading levels
123456789101112
<!-- Only process h2 headings --><heading-linkslevels="h2"><h2>This gets an anchor</h2><h3>This does not</h3></heading-links><!-- Process h2, h3, and h4 --><heading-linkslevels="h2,h3,h4"><h2>Anchor link</h2><h3>Anchor link</h3><h4>Anchor link</h4></heading-links>
Auto-generated IDs
Headings without an idattribute get one generated from their text content. Existing IDs are preserved. The slug is Unicode-aware: letters in any script keep their accents (Café crème → café-crème, 日本語の見出し stays as is), punctuation and emoji are dropped, whitespace becomes a hyphen, and the result is capped at 50 characters. A heading with no letters or numbers (emoji only) gets section. Duplicates get -1, -2… suffixes.
The site link checker (scripts/check-links.mjs) mirrors this rule, including the suffixes, so links to generated IDs are validated at build time.
ID handling
12345
<!-- Existing IDs are preserved --><heading-links><h2id="custom-id">This keeps its ID</h2><h3>This gets an auto-generated ID</h3></heading-links>
Events
Event
Detail
Description
heading-links:navigate
{ id: string, url: string, heading: HTMLElement }
Fired when an anchor is activated, after the fragment navigation and before the clipboard write
Anchor icons appear on heading hover, on keyboard focus, and always on touch (no-hover) devices
Activating an anchor follows the fragment like a native link: :target updates, a history entry is added, the heading is focused, and the scroll is smooth (instant under prefers-reduced-motion). It stays on the page under <base href>.
Every activation writes to the clipboard: the absolute page URL plus the section hash
Ctrl/Cmd/Shift/Alt-clicks and middle clicks are left to the browser (open in new tab, etc.) and do not copy
A brief checkmark icon (data-state="copied" on the anchor) confirms the copy succeeded
Headings are skipped inside <dialog>, [data-toc-ignore], <browser-window> (demo content, not page sections) and a nested <heading-links> (which owns its own headings)
A MutationObserver watches for dynamically added headings
Accessibility
The heading keeps its own text as its accessible name: the text is wrapped in a .heading-text span the heading is labelled by, so the anchor does not add to it
Each anchor is named Copy link to [heading text] via aria-labelledby (prefix from data-label-anchor), so it follows text changes
Headings are made focusable with tabindex="-1" for keyboard navigation to anchored sections
Copy confirmation is announced through a role="status" live region outside the link
Focus-visible styles on anchor links
Styling
The anchor uses the .heading-anchor class. It is hidden by default (opacity: 0) and revealed on hover, focus, :target, and on no-hover devices. Headings get scroll-margin-block-start: calc(var(--site-header-height) + var(--size-m)) so a jump clears a sticky header.
Custom styling
123456789
/* Custom anchor icon color */heading-links .heading-anchor {color: var(--color-primary);}/* Always show anchors (instead of hover-only) */heading-links .heading-anchor {opacity: 1;}
Related
<page-toc> — Table of contents generator (pairs well with heading-links)