This file provides guidance to Claude Code (claude.ai/code) 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 npm scripts for building, testing, or linting
- Changes to source files are immediately usable
- Test by linking the package locally and using in a Docusaurus project
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