# MkDocs Copy to LLM Plugin
[](https://github.com/leonardocustodio/mkdocs-copy-to-llm/actions/workflows/tests.yml)
[](https://codecov.io/gh/leonardocustodio/mkdocs-copy-to-llm)
[](https://badge.fury.io/py/mkdocs-copy-to-llm)
[](https://pypi.org/project/mkdocs-copy-to-llm/)
A MkDocs plugin that adds "Copy to LLM" buttons to your documentation, making it easy to copy code blocks and entire pages in formats optimized for Large Language Models (LLMs).
This package was inspired by [Docus](https://github.com/nuxtlabs/docus) by NuxtLabs and made for [Polkadot Documentation](https://docs.polkadot.com).
## Features
- **Copy to LLM buttons for code blocks** — Adds a button next to each code block to copy the code with context
- **Copy entire page** — Adds a split button at the top of each page with multiple copy options:
- Copy page content as Markdown
- Copy markdown link
- Open in ChatGPT
- Open in Claude
- View raw markdown
- **Smart formatting** — Automatically formats content with proper context for LLM consumption
- **Visual feedback** — Shows success indicators and toast notifications
- **Mobile responsive** — Works seamlessly on all device sizes
## Installation
Install the plugin using pip:
```bash
pip install mkdocs-copy-to-llm
```
### Optional Dependencies
For asset minification in production builds:
```bash
pip install mkdocs-copy-to-llm[minify]
# or separately:
pip install jsmin csscompressor
```
## Configuration
Add the plugin to your `mkdocs.yml`:
```yaml
plugins:
- copy-to-llm
```
That's it! The plugin will automatically add copy buttons to all your pages and code blocks.
### Configuration Options (Optional)
#### Color Customization
You can customize the colors to match your theme:
```yaml
plugins:
- copy-to-llm:
button_bg_color: "#ffffff" # Button background color
button_hover_color: "#0969da" # Button hover color
toast_bg_color: "#0969da" # Toast notification background
toast_text_color: "#ffffff" # Toast notification text color
```
Colors can be specified as:
- Hex values: `#0969da` or `#09d`
- RGB values: `rgb(9, 105, 218)` or `rgba(9, 105, 218, 0.5)`
- CSS color names: `blue`, `red`, `darkslategray`, etc.
- CSS variables: `var(--md-primary-fg-color)`
The plugin validates all color values and will show an error if an invalid format is provided.
Example configurations for popular themes:
**Material for MkDocs:**
```yaml
plugins:
- copy-to-llm:
button_hover_color: "var(--md-primary-fg-color)"
toast_bg_color: "var(--md-primary-fg-color)"
```
**MkDocs Default Theme:**
```yaml
plugins:
- copy-to-llm:
button_bg_color: "#f5f5f5"
button_hover_color: "#3f51b5"
toast_bg_color: "#3f51b5"
```
#### Repository URL Configuration
For the "Copy Markdown link" and "Open in ChatGPT/Claude" features to work correctly, you can specify your repository's raw content URL:
```yaml
plugins:
- copy-to-llm:
repo_url: "https://raw.githubusercontent.com/owner/repo/branch"
```
If not configured, the plugin will try to:
1. Detect the repository URL from edit links in your theme
2. Use repository links found on the page
3. Fall back to constructing URLs based on the current path
**Note**: The URL should point to the raw content base URL without the trailing slash. For GitHub repositories, this is typically `https://raw.githubusercontent.com/owner/repo/branch`.
#### Asset Minification
The plugin can automatically minify JavaScript and CSS files in production builds when the optional dependencies are installed:
```bash
# Install minification dependencies (optional)
pip install jsmin csscompressor
```
```yaml
plugins:
- copy-to-llm:
minify: true # Default is true
```
Minification is automatically disabled when running `mkdocs serve` for easier debugging. If the minification libraries are not installed, the plugin will work normally but without minification.
#### Analytics Integration
Track copy events to understand how users interact with your documentation:
```yaml
plugins:
- copy-to-llm:
analytics: true # Default is false
```
When enabled, the plugin will send copy events to your analytics platform (if configured):
- **Event name**: `copy_to_llm`
- **Event category**: `engagement`
- **Event label**: `code_block`, `page_content`, `markdown_content`, or `markdown_link`
- **Event value**: Length of copied content
Supported analytics platforms:
- Google Analytics (gtag.js)
- Plausible Analytics
**Important**: Analytics tracking is opt-in and disabled by default. The plugin will only track events when:
1. The `analytics` option is explicitly set to `true` in your configuration
2. An analytics platform is already configured on your site
This ensures user privacy is respected and no tracking occurs without explicit consent.
## How It Works
The plugin automatically:
1. Injects the necessary JavaScript and CSS files
2. Adds a split button to the main page title
3. Handles all copy operations with proper formatting
## Customization
The plugin uses CSS variables from your MkDocs theme. It integrates seamlessly with the Material theme for MkDocs.
## Development
### Setup
```bash
# Clone the repository
git clone https://github.com/leonardocustodio/mkdocs-copy-to-llm.git
cd mkdocs-copy-to-llm
# Install development dependencies
make install-dev
```
### Available Commands
```bash
make help # Show all available commands
make test # Run tests with coverage
make lint # Run linting checks
make format # Format code with Ruff
```
### Pre-commit Hooks
The project uses pre-commit hooks to ensure code quality:
```bash
pre-commit install # Install hooks (done automatically by make install-dev)
pre-commit run --all-files # Run all hooks manually
```
## Accessibility
The plugin is designed with accessibility in mind:
- All buttons have proper ARIA labels
- Full keyboard navigation support
- Screen reader friendly
- Focus management for dropdown menus
- Escape key closes dropdowns
## License
Apache License 2.0
Raw data
{
"_id": null,
"home_page": null,
"name": "mkdocs-copy-to-llm",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "mkdocs, plugin, documentation, llm, copy, ai, chatgpt, claude",
"author": null,
"author_email": "Leonardo Custodio <leonardo.custodio@parity.io>, David Castro <davidcastro@parity.io>, Karim Jedda <karim@parity.io>",
"download_url": "https://files.pythonhosted.org/packages/29/da/898a4ef1a64417889e1c9ba7f44d899c8ebeccd0bf43d132745be1d571a8/mkdocs_copy_to_llm-0.2.1.tar.gz",
"platform": null,
"description": "# MkDocs Copy to LLM Plugin\n\n[](https://github.com/leonardocustodio/mkdocs-copy-to-llm/actions/workflows/tests.yml)\n[](https://codecov.io/gh/leonardocustodio/mkdocs-copy-to-llm)\n[](https://badge.fury.io/py/mkdocs-copy-to-llm)\n[](https://pypi.org/project/mkdocs-copy-to-llm/)\n\nA MkDocs plugin that adds \"Copy to LLM\" buttons to your documentation, making it easy to copy code blocks and entire pages in formats optimized for Large Language Models (LLMs).\n\nThis package was inspired by [Docus](https://github.com/nuxtlabs/docus) by NuxtLabs and made for [Polkadot Documentation](https://docs.polkadot.com).\n\n## Features\n\n- **Copy to LLM buttons for code blocks** \u2014 Adds a button next to each code block to copy the code with context\n- **Copy entire page** \u2014 Adds a split button at the top of each page with multiple copy options:\n - Copy page content as Markdown\n - Copy markdown link\n - Open in ChatGPT\n - Open in Claude\n - View raw markdown\n- **Smart formatting** \u2014 Automatically formats content with proper context for LLM consumption\n- **Visual feedback** \u2014 Shows success indicators and toast notifications\n- **Mobile responsive** \u2014 Works seamlessly on all device sizes\n\n## Installation\n\nInstall the plugin using pip:\n\n```bash\npip install mkdocs-copy-to-llm\n```\n\n### Optional Dependencies\n\nFor asset minification in production builds:\n\n```bash\npip install mkdocs-copy-to-llm[minify]\n# or separately:\npip install jsmin csscompressor\n```\n\n## Configuration\n\nAdd the plugin to your `mkdocs.yml`:\n\n```yaml\nplugins:\n - copy-to-llm\n```\n\nThat's it! The plugin will automatically add copy buttons to all your pages and code blocks.\n\n### Configuration Options (Optional)\n\n#### Color Customization\n\nYou can customize the colors to match your theme:\n\n```yaml\nplugins:\n - copy-to-llm:\n button_bg_color: \"#ffffff\" # Button background color\n button_hover_color: \"#0969da\" # Button hover color\n toast_bg_color: \"#0969da\" # Toast notification background\n toast_text_color: \"#ffffff\" # Toast notification text color\n```\n\nColors can be specified as:\n- Hex values: `#0969da` or `#09d`\n- RGB values: `rgb(9, 105, 218)` or `rgba(9, 105, 218, 0.5)`\n- CSS color names: `blue`, `red`, `darkslategray`, etc.\n- CSS variables: `var(--md-primary-fg-color)`\n\nThe plugin validates all color values and will show an error if an invalid format is provided.\n\nExample configurations for popular themes:\n\n**Material for MkDocs:**\n```yaml\nplugins:\n - copy-to-llm:\n button_hover_color: \"var(--md-primary-fg-color)\"\n toast_bg_color: \"var(--md-primary-fg-color)\"\n```\n\n**MkDocs Default Theme:**\n```yaml\nplugins:\n - copy-to-llm:\n button_bg_color: \"#f5f5f5\"\n button_hover_color: \"#3f51b5\"\n toast_bg_color: \"#3f51b5\"\n```\n\n#### Repository URL Configuration\n\nFor the \"Copy Markdown link\" and \"Open in ChatGPT/Claude\" features to work correctly, you can specify your repository's raw content URL:\n\n```yaml\nplugins:\n - copy-to-llm:\n repo_url: \"https://raw.githubusercontent.com/owner/repo/branch\"\n```\n\nIf not configured, the plugin will try to:\n1. Detect the repository URL from edit links in your theme\n2. Use repository links found on the page\n3. Fall back to constructing URLs based on the current path\n\n**Note**: The URL should point to the raw content base URL without the trailing slash. For GitHub repositories, this is typically `https://raw.githubusercontent.com/owner/repo/branch`.\n\n#### Asset Minification\n\nThe plugin can automatically minify JavaScript and CSS files in production builds when the optional dependencies are installed:\n\n```bash\n# Install minification dependencies (optional)\npip install jsmin csscompressor\n```\n\n```yaml\nplugins:\n - copy-to-llm:\n minify: true # Default is true\n```\n\nMinification is automatically disabled when running `mkdocs serve` for easier debugging. If the minification libraries are not installed, the plugin will work normally but without minification.\n\n#### Analytics Integration\n\nTrack copy events to understand how users interact with your documentation:\n\n```yaml\nplugins:\n - copy-to-llm:\n analytics: true # Default is false\n```\n\nWhen enabled, the plugin will send copy events to your analytics platform (if configured):\n- **Event name**: `copy_to_llm`\n- **Event category**: `engagement`\n- **Event label**: `code_block`, `page_content`, `markdown_content`, or `markdown_link`\n- **Event value**: Length of copied content\n\nSupported analytics platforms:\n- Google Analytics (gtag.js)\n- Plausible Analytics\n\n**Important**: Analytics tracking is opt-in and disabled by default. The plugin will only track events when:\n1. The `analytics` option is explicitly set to `true` in your configuration\n2. An analytics platform is already configured on your site\n\nThis ensures user privacy is respected and no tracking occurs without explicit consent.\n\n## How It Works\n\nThe plugin automatically:\n1. Injects the necessary JavaScript and CSS files\n2. Adds a split button to the main page title\n3. Handles all copy operations with proper formatting\n\n## Customization\n\nThe plugin uses CSS variables from your MkDocs theme. It integrates seamlessly with the Material theme for MkDocs.\n\n## Development\n\n### Setup\n\n```bash\n# Clone the repository\ngit clone https://github.com/leonardocustodio/mkdocs-copy-to-llm.git\ncd mkdocs-copy-to-llm\n\n# Install development dependencies\nmake install-dev\n```\n\n### Available Commands\n\n```bash\nmake help # Show all available commands\nmake test # Run tests with coverage\nmake lint # Run linting checks\nmake format # Format code with Ruff\n```\n\n### Pre-commit Hooks\n\nThe project uses pre-commit hooks to ensure code quality:\n\n```bash\npre-commit install # Install hooks (done automatically by make install-dev)\npre-commit run --all-files # Run all hooks manually\n```\n\n## Accessibility\n\nThe plugin is designed with accessibility in mind:\n\n- All buttons have proper ARIA labels\n- Full keyboard navigation support\n- Screen reader friendly\n- Focus management for dropdown menus\n- Escape key closes dropdowns\n\n## License\n\nApache License 2.0\n",
"bugtrack_url": null,
"license": null,
"summary": "MkDocs plugin to add 'Copy to LLM' buttons to documentation",
"version": "0.2.1",
"project_urls": {
"Bug Tracker": "https://github.com/leonardocustodio/mkdocs-copy-to-llm/issues",
"Changelog": "https://github.com/leonardocustodio/mkdocs-copy-to-llm/releases",
"Documentation": "https://github.com/leonardocustodio/mkdocs-copy-to-llm#readme",
"Homepage": "https://github.com/leonardocustodio/mkdocs-copy-to-llm",
"Repository": "https://github.com/leonardocustodio/mkdocs-copy-to-llm"
},
"split_keywords": [
"mkdocs",
" plugin",
" documentation",
" llm",
" copy",
" ai",
" chatgpt",
" claude"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "e020153a37c3253190fcf3bc7242786351be2e33ffab23d8e9f811ac884e22d5",
"md5": "0c2846c4cb26351eb037010538b3f34b",
"sha256": "9ffd01979ed0d4b2917ce32e7ee91ea508b4678019c2a7f4d0c095ebf3be99e4"
},
"downloads": -1,
"filename": "mkdocs_copy_to_llm-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0c2846c4cb26351eb037010538b3f34b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 24541,
"upload_time": "2025-07-25T14:32:24",
"upload_time_iso_8601": "2025-07-25T14:32:24.013470Z",
"url": "https://files.pythonhosted.org/packages/e0/20/153a37c3253190fcf3bc7242786351be2e33ffab23d8e9f811ac884e22d5/mkdocs_copy_to_llm-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "29da898a4ef1a64417889e1c9ba7f44d899c8ebeccd0bf43d132745be1d571a8",
"md5": "97dd1fea77234c50d0320fb5e1102d35",
"sha256": "67e9523afc18dfefec1990c214561bec5f722d2becb3c536deaf032355716bb5"
},
"downloads": -1,
"filename": "mkdocs_copy_to_llm-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "97dd1fea77234c50d0320fb5e1102d35",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 32444,
"upload_time": "2025-07-25T14:32:25",
"upload_time_iso_8601": "2025-07-25T14:32:25.082279Z",
"url": "https://files.pythonhosted.org/packages/29/da/898a4ef1a64417889e1c9ba7f44d899c8ebeccd0bf43d132745be1d571a8/mkdocs_copy_to_llm-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-25 14:32:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "leonardocustodio",
"github_project": "mkdocs-copy-to-llm",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "mkdocs-copy-to-llm"
}