[docs] Add "Copy page as markdown" button#8102
Open
dokson wants to merge 1 commit into
Open
Conversation
Add a Copy page button to every docs page that hands the reader an LLM/IDE-friendly markdown blob of the current page. Builds on cameronjoyner's Documentalist pipeline by attaching a sourceMarkdown field to each PageData at build time and rendering an AnchorButton next to "Edit this page". Pipeline (docs-data): for every page produced by the MarkdownPlugin, read the source .mdx via PageData.sourcePath and run it through stripDocumentalistTags, which replaces top-level @reactDocs/@reactExample/@interface/@css lines with HTML comment placeholders ("see online docs") so the exported markdown is valid for tooling and self-documenting. Lines inside fenced code blocks are left untouched, so Sass @use/@import in code samples are preserved. The function is in its own module (markdownExport.mts) with a vitest test, so importing it does not trigger the top-level build code in compile-docs-data.mts. UI (docs-theme): a new CopyPageMarkdownButton renders a Blueprint AnchorButton with a clipboard icon and "Copy page" label, swapping to a tick + "Copied!" tooltip for 1.5s on success. Hidden when the page has no sourceMarkdown. Wiring (docs-app): BlueprintDocs.renderPageActions now renders the new button alongside the existing "Edit this page" link. Fixes palantir#7687.
Generate changelog in
|
Author
|
@cameronjoyner — implements #7687 starting from your "Copy page" idea. The |
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.
Summary
Fixes #7687.
Adds a "Copy page" button to every docs page that hands the reader an LLM/IDE-friendly markdown blob of the current page, like Radix and Groq do.
Pipeline (
docs-data)For every page produced by the
MarkdownPlugin, the build now reads the source.mdxviaPageData.sourcePath, runs it through a newstripDocumentalistTagshelper, and attaches the result assourceMarkdownon the page object. The helper replaces top-level@reactDocs/@reactExample/@interface/@csslines with HTML comment placeholders (<!-- Interactive widget: ... (see online docs) -->) so the exported markdown stays valid and self-documenting. Lines inside fenced code blocks are left untouched, so Sass@use/@importin code samples are preserved.stripDocumentalistTagslives in its own module (markdownExport.mts) with a dedicatedmarkdownExport.test.ts, so importing it for testing does not trigger the top-level build code incompile-docs-data.mts.UI (
docs-theme)A new
CopyPageMarkdownButtonrenders a BlueprintAnchorButtonwith a clipboard icon and "Copy page" label. On click it writessourceMarkdownto the clipboard and swaps the icon to a tick with a "Copied!" tooltip for 1.5s. The button is hidden whensourceMarkdownis undefined (e.g. transient pages or build-time skip).Wiring (
docs-app)BlueprintDocs.renderPageActionsnow renders the new button alongside the existing "Edit this page" link, so every page action area gets both controls.Test plan
pnpm --filter @blueprintjs/docs-data run testformarkdownExport.test.ts— 3/3 passed (existing failures innavHelpers.test.tsare pre-existing and unrelated)docs-data:compileissue with Node 25; the repo's.nvmrcpins 24.14.1)Out of scope
A "View page as markdown" link or the dropdown variant from the issue's second screenshot. Once the basic
sourceMarkdownplumbing is in place those are easy follow-ups, happy to do them in a separate PR if maintainers want.