feat(docs): add "Copy as Markdown" button to docs pages#1067
Merged
Conversation
Add a "Copy as Markdown" button next to each docs page title that copies a clean Markdown version of the page to the clipboard, reusing the same conversion as the llms.txt export (custom <Youtube>/<Tweet> shortcodes become plain links). - Extract the shared content-level Markdown transforms into src/lib/llms/page-markdown.ts and refactor the llms-txt post-process integration to reuse them, so output stays identical everywhere. - Also convert the <Youtube url="..."> variant (previously left as raw JSX in llms output), fixing a latent gap surfaced by this feature. - Render the button in the page-title row (placement/appearance modelled on the starlight-copy-button plugin) with "Copied!" feedback and a Plausible event. - Embed the page Markdown inline so copying works the same in dev and prod. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a “Copy as Markdown” control to Starlight docs pages by generating per-page Markdown using the same transforms as the llms*.txt export, so users can quickly copy a clean Markdown representation of a page.
Changes:
- Introduces shared Markdown transform utilities and a
docBodyToMarkdown(entry)composer for docs entries. - Refactors
llms-txt-post-processto reuse the shared transforms to keep outputs identical. - Updates the custom
PageTitlecomponent to render the Copy button, embed page Markdown as JSON, and add client-side copy + feedback + analytics.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| docs/src/lib/llms/page-markdown.ts | New shared Markdown transform module + page-to-Markdown composer used by both the button and llms export. |
| docs/src/integrations/llms-txt-post-process.ts | Refactors llms post-processing to call the shared transforms. |
| docs/src/components/starlight/PageTitle.astro | Renders the “Copy as Markdown” button, embeds JSON payload, and adds inline copy script/styles. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address PR review feedback: - convertDirectivesToBlockquotes/stripDirectives now match 3+ colons and an optional bracketed custom title (e.g. ::::tip[Title]); previously these leaked as raw :::/:::: syntax into copied and llms Markdown. - Tweet shortcode links now use the canonical /i/status/<id> permalink form. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a Copy as Markdown button to every docs content page. It sits above the page title, right-aligned, and copies a clean Markdown version of the page to the clipboard with brief "Copied!" feedback — so developers and LLMs can grab a page easily.
Placement/appearance is modelled on the
starlight-copy-buttonplugin, but the Markdown is generated by reusing our existingllms.txtconversion rather than a new client-side HTML→Markdown converter (no new dependencies).How
src/lib/llms/page-markdown.ts(new) — extracts the content-level Markdown transforms (<Youtube>/<Tweet>→ plain links, JSX-artifact stripping,:::directives → blockquotes, etc.) into a shared module, plusdocBodyToMarkdown(entry)that composes a page exactly like the llms generator (# title/> description/ body).src/integrations/llms-txt-post-process.ts— refactored to reuse those helpers, so the button and the llms export produce identical output. Also fixes a latent gap: the<Youtube url="…">variant was previously left as raw JSX inllms-full.txt; now bothidandurlvariants convert.src/components/starlight/PageTitle.astro— renders the button, embeds the page Markdown inline (works identically inastro devand production, no extra route), scoped theme-matched styles, an inline copy script (with a non-secure-context fallback), a visually-hiddenaria-liveregion for screen readers, and a PlausibleCopy as Markdownevent on success.Note on approach
Initially implemented as a static
.mdendpoint, but Starlight's/docs/*catch-all shadows it inastro dev(404), so the Markdown is embedded inline instead — largest page ~12.6 KB, most 2–6 KB, gzips to a few KB.Verification
lint,format:check,typecheck(0 errors),build,knip.<Youtube>(both variants) renders as[title](youtube link), not raw markup.JSON.parse(checked on the 12.6 KB code-heavy CLI page).Before/after screenshot to be added.
🤖 Generated with Claude Code