fix(docs): export clean selected-language markdown from Copy page button#460
Open
g-despot wants to merge 1 commit into
Open
fix(docs): export clean selected-language markdown from Copy page button#460g-despot wants to merge 1 commit into
g-despot wants to merge 1 commit into
Conversation
The "Copy page" button scraped `article.innerText`, capturing page chrome (breadcrumbs, version badge, mobile TOC, footer "Edit this page"/tags) and emitting rendered text instead of markdown. Rewrite `copyPageAsMarkdown` to scope to `.theme-doc-markdown` and convert with turndown (dynamically imported for SSR safety), capturing only the currently-selected code language. - Strip hidden language panels, default-tab chrome (role=tablist / hidden), decorative icons, the code-tab header controls, and Cloud/Academy badges - Preserve Prism code blocks as fenced blocks with language + line breaks - Add an `error` copy state, a clipboard guard, and aria-live on the status - Add a `data-copy-exclude` opt-out marker (CloudOnlyBadge, AcademyBadge)
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
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.
Problem
The docs "Copy page" button copied page chrome and didn't produce real markdown. Reported by the team:
Root cause:
copyPageAsMarkdownscrapeddocument.querySelector("article").innerText. The<article>wrapper includes breadcrumbs, the version badge, the mobile TOC, and the footer ("Edit this page", tags), andinnerTextis rendered text, not markdown (code fences, heading#, and link syntax are all lost).Fix
Rewrote
copyPageAsMarkdownto produce clean markdown:.theme-doc-markdown(the content body; page chrome is a sibling outside it).turndown+turndown-plugin-gfm, dynamically imported inside the handler so the site still server-renders at build time (turndown touches the DOM).[aria-hidden="true"].[role="tablist"],[hidden]), decorative icons (img[alt=""]), the code-tab header controls (the.codecontainer header — language selector, "API docs" link, "More info"), and Cloud/Academy badges.errorcopy state ("Copy failed"), anavigator.clipboardguard, andaria-live="polite"on the status label.A reusable
data-copy-excludeopt-out marker was added toCloudOnlyBadgeandAcademyBadgeso their text no longer leaks into the copied markdown.Verification
yarn buildpasses (exit 0).Out of scope / follow-ups
llms-txtplugin path was intentionally not used, to keep this change self-contained.sourceand pinsmain(version drift); the prompts-variant copy doesn't use the new error state.Files
src/components/ContextualMenu/index.js— the fixsrc/components/CloudOnlyBadge/index.jsx,src/components/AcademyBadge/index.jsx—data-copy-excludemarkerspackage.json,yarn.lock— addturndown+turndown-plugin-gfm