This file provides guidance to coding agents when working with code in this repository.
This is a Docusaurus plugin that adds a "Copy page" button to documentation sites, allowing users to extract page content as markdown for use with LLMs and AI tools.
- src/index.js - Main plugin entry point that registers the plugin with Docusaurus and passes options to the client-side code
- src/CopyPageButton.js - React component that renders the copy button and dropdown with actions (copy, view, open in AI tools)
- src/client.js - Client-side injection logic that automatically adds the button to the Docusaurus sidebar
- src/styles.module.css - CSS styles for the copy button and dropdown
This is a client-side Docusaurus plugin that:
- Registers itself via the main plugin function in
src/index.js - Uses
getClientModules()to inject client-side code - Uses
injectHtmlTags()to pass configuration options to the browser - Auto-injects the copy button into the table of contents sidebar
The plugin uses a sophisticated injection system in src/client.js:
- Fast injection for SPA navigation when sidebar already exists
- Reliable injection for page refreshes with retry logic and timeout handling
- Responsive handling for layout changes and mobile/desktop transitions
- Route change detection using multiple strategies (popstate, docusaurus events, URL monitoring)
The CopyPageButton.js component includes comprehensive markdown conversion logic that:
- Extracts main content from Docusaurus article containers
- Removes navigation, UI elements, and buttons
- Converts HTML to clean markdown with proper formatting
- Handles code blocks, tables, lists, and admonitions
- Cleans up various text encoding issues
Since this is a pure Docusaurus plugin with no build step:
- No build step or linter; changes to source files are immediately usable
npm testruns the Node test-runner tests intest/;npm run pack:checkverifies the published tarball contents- CI (
.github/workflows/ci.yml) runs both on every push tomainand every PR - For behavior that CI cannot cover, test by linking the package locally and using it in a Docusaurus project
Before opening a PR to add this plugin to another documentation site, screen the target repository's base branch for overlapping features.
Required checks:
- Search for existing page-level copy or AI actions, including
CopyPageButton,DocActionsDropdown,copy as markdown,copy page,Open in ChatGPT,Open in Claude,Open in Gemini, anddocusaurus-plugin-copy-page-button. - Search for adjacent LLM documentation export features, including
llms.txt,llms-full.txt,docusaurus-plugin-llms,markdown-export, and customllmorllmsplugins. - Check whether this account already opened a PR in that repository with
docusaurus-plugin-copy-page-button.
Do not open a PR when the site already has an equivalent page-level copy/open-in-AI UI. If the site only has llms.txt or static markdown exports, the PR may still be useful, but the PR body must explicitly mention the existing feature and explain that this plugin adds a page-level copy/open UI instead of a corpus export.
Never open an outreach PR blindly. In addition to the feature-overlap screen above, check the target repo's contribution rules and health — a clean feature-fit is not enough if the repo will auto-close the PR or the project is dead:
- CONTRIBUTING.md / PR template — read
CONTRIBUTING.md(root or.github/) and any.github/PULL_REQUEST_TEMPLATE*. Follow the template. - CLA / DCO — flag any CLA-assistant / EasyCLA (common in OpenJS, CNCF, LF, Meta, Microsoft, Salesforce orgs) or DCO
Signed-off-byrequirement. If DCO, commit withgit commit -s. Note the CLA so the user knows to sign it. - Issue-first policy — many projects explicitly close feature PRs opened without a pre-approved issue. If so, open a short enhancement issue and wait for maintainer go-ahead instead of filing the PR cold.
- Commit / PR-title conventions — use Conventional Commits (
docs:/feat:) or semantic PR titles where the repo enforces them (commitlint, semantic-pr, label-required CI). - Project health — skip / deprioritize repos that are archived, in wind-down/rename, superseded by a successor repo, or stale (no commits in many months). Consider the successor repo instead.
Record per-target policy findings (proposal-first gates, CLA orgs, dead/renamed projects) in memory so they aren't re-discovered every cycle.
- Fork with a custom
--fork-name(default names collide across targets); verify the fork viagh api repos/<fork> -q .fork(the fork command may print no stdout but still succeed). - Add the plugin to the
pluginsarray and pin it in the docspackage.jsondependencies; update the lockfile so the target's frozen-lockfile CI passes. - Run
docusaurus buildlocally and confirm it succeeds. The button mounts client-side, so it will NOT appear in static HTML — a clean build is the pass criterion. If the build fails, prove it fails identically WITHOUT the change (pre-existing) before proceeding, and do not claim a passing build in the PR body if you could not run one. - Write the PR body to
/home/ubuntu/pr-drafts/<target>.mdand wait for explicit user confirmation before runninggh pr create. Never draft-in-chat and file in one step.
npm linkin this repositorynpm link docusaurus-plugin-copy-page-buttonin target Docusaurus project- Add plugin to
docusaurus.config.js - Start Docusaurus development server to test changes
The plugin accepts a customStyles option for styling the button, dropdown, and container elements. Positioning styles from button config are automatically moved to the container for proper layout control.
- Only runs in browser environment (uses
ExecutionEnvironment.canUseDOM) - Requires React 18+ and Docusaurus 3.0+ (specified in peerDependencies)
- Uses modern browser APIs like clipboard and DOM manipulation