Skip to content

Make imports and identifiers clickable in code blocks - #91

Merged
randomdevpete merged 2 commits into
masterfrom
task-684-clickable-imports-and-jarl-references-in-code
Aug 19, 2026
Merged

Make imports and identifiers clickable in code blocks#91
randomdevpete merged 2 commits into
masterfrom
task-684-clickable-imports-and-jarl-references-in-code

Conversation

@randomdevpete

Copy link
Copy Markdown
Owner

Summary

Make imports and identifiers clickable in demo source code, guides, and API reference pages:

  • Clicking a jarl-atoms/jarl-react identifier links to its API reference entry
  • Clicking a local relative import link to that file on GitHub
  • The API link mapping is derived from the same slugify function that renders heading anchors, so it cannot drift

How it works

Two new source files track clickable targets:

  • Generated api-links map: scanned from the API reference's own ### \Name`` headings (inherits anchors automatically)
  • Generated source-files list: walks packages/docs/src/ to resolve relative imports to GitHub blob URLs

The linkifyHtml function post-processes highlighted code to wrap identifiers/imports in anchors, tracking which hljs-* class is open to avoid linking inside comments.

Style guide compliance

No style guide exceptions. Comments are appropriately scoped, docblocks on public exports only, DRY applied (slugify extracted into shared module), no dead code or unused imports.

// Regenerates the source-file list `lib/localSource.ts` resolves imports against. Runs at
// build start and again whenever a file is added or removed under src/, mirroring
// apiReferencePlugin.mjs's own regenerate-on-change shape.
import path from "node:path";

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this and sourceLinks.mjs be reimplemented in typescript?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e5418bb

…their API reference

Highlighted code (demo source, guide/README fences, the API reference itself) now links any
recognised export name to its API reference anchor, reusing the same #slug scheme heading
anchors already use. slug.ts pulls the shared slugify out of Markdown.tsx so apiLinks.ts can
derive the manifest straight from the generated reference's own headings, never drifting from
the anchors actually rendered.

Ticket: 684
@randomdevpete
randomdevpete force-pushed the task-684-clickable-imports-and-jarl-references-in-code branch 2 times, most recently from 3b92725 to 0b77005 Compare August 19, 2026 00:51
CodeBlock now accepts the repo path of the file it's showing (DemoPage already knew its own
demo's), and links a relative import specifier straight to that file on GitHub. The target
file list is generated at build/dev time (sourceLinksPlugin.ts, mirroring
apiReferencePlugin.mjs's own shape) so resolution never depends on Vite's module graph at
render time.

Ticket: 684
@randomdevpete
randomdevpete force-pushed the task-684-clickable-imports-and-jarl-references-in-code branch from 0b77005 to e5418bb Compare August 19, 2026 00:53
@randomdevpete
randomdevpete merged commit 2cc8dfb into master Aug 19, 2026
5 checks passed
@randomdevpete
randomdevpete deleted the task-684-clickable-imports-and-jarl-references-in-code branch August 19, 2026 11:55
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.

1 participant