Development
Setting Up Development Environment
-
Clone the repository:
-
Install uv (if not already installed):
-
Sync dependencies and create virtual environment:
This will automatically: - Create a virtual environment - Install the package in development mode - Install all dependencies (including dev dependencies)
Project Structure
mkdocs-copy-markdown/
├── mkdocs_copy_markdown/
│ ├── __init__.py
│ └── plugin.py
├── docs/
│ ├── index.md
│ ├── installation.md
│ ├── configuration.md
│ └── development.md
├── tests/
│ └── test_plugin.py
├── mkdocs.yml
├── pyproject.toml
├── setup.py
├── MANIFEST.in
├── .gitignore
└── README.md
Plugin Architecture
The plugin uses MkDocs' event system to inject the copy functionality:
Core Components
- Plugin Class:
CopyMarkdownPluginextendsBasePlugin - Event Hook:
on_page_contentmodifies rendered HTML - JavaScript: Handles clipboard operations with fallbacks
- CSS: Provides button styling
Event Flow
- MkDocs processes markdown → HTML
on_page_contentis called with the HTML- Plugin injects button HTML, JavaScript, and CSS
- Returns modified HTML to MkDocs
Testing
Manual Testing
Test the plugin with this documentation site:
Visit http://localhost:8000 and test the copy functionality.
Unit Testing
Run the test suite:
Testing with Different Themes
Test with different themes by temporarily adding them:
# Test with Material theme (already included)
uv run mkdocs serve
# Test with other themes
uv add mkdocs-rtd-dropdown --dev
uv run mkdocs serve -f test-configs/readthedocs.yml
Code Style
The project follows standard Python conventions:
- PEP 8 for code style
- Type hints where appropriate
- Docstrings for public methods
- Clear variable and function names
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
Release Process
- Update version in
pyproject.tomland__init__.py - Update
CHANGELOG.md - Create a git tag:
git tag v0.2.0 - Push tags:
git push --tags - GitHub Actions will automatically:
- Run tests across Python versions
- Build the package
- Publish to PyPI using trusted publishing
Manual build (for testing):