Convert Markdown to beautiful, interactive HTML and PDF with TOC, dark/light mode, Mermaid diagrams, and syntax highlighting
Project description
mk2html
A powerful Python CLI tool that converts Markdown files to beautiful, interactive HTML documents with Table of Contents, Dark/Light mode, Mermaid diagram support, and syntax highlighting.
โจ Features
- ๐ Dark/Light Mode - Toggle between themes with persistence via localStorage
- ๐ Auto Table of Contents - Generated from headings with active section highlighting
- ๐ Mermaid Diagrams - Flowcharts, sequence, class, gantt, pie, state diagrams
- ๐จ Syntax Highlighting - Language-aware code highlighting with Highlight.js
- ๐ข Line Numbers - Code blocks include line numbers
- ๐ Progress Bar - Shows reading progress as you scroll
- ๐ Back to Top - Floating button for quick navigation
- ๐ฑ Responsive Design - Mobile-friendly with collapsible sidebar
- ๐จ๏ธ Print Styles - Clean output when printing
- ๐ Click-to-Copy - Click any heading to copy its link
๐ฆ Installation
Prerequisites
- Python 3.7 or higher
- pip (Python package manager)
Install Dependencies
pip install -r requirements.txt
Or install manually:
pip install markdown Pygments
Make Executable (Optional)
chmod +x mk2html.py
Create Global Symlink (Optional)
ln -s $(pwd)/mk2html.py /usr/local/bin/mk2html
๐ Usage
Basic Usage
python3 mk2html.py input.md
This creates input.html in the same directory.
Specify Output File
python3 mk2html.py docs.md -o documentation.html
Custom Title
python3 mk2html.py guide.md --title "User Guide"
Start with Dark Theme
python3 mk2html.py report.md --theme dark
Disable Mermaid Support
python3 mk2html.py spec.md --no-mermaid
Read from Stdin
cat input.md | python3 mk2html.py - -o output.html
Quiet Mode (for scripts)
python3 mk2html.py input.md -q
Full Options
python3 mk2html.py --help
usage: mk2html [-h] [-o FILE] [-t TITLE] [--theme {light,dark}] [--no-mermaid]
[--no-toc] [-q] [-v]
INPUT
Convert Markdown to beautiful, interactive HTML with TOC and Mermaid support.
positional arguments:
INPUT Input Markdown file (use "-" for stdin)
optional arguments:
-h, --help show this help message and exit
-o FILE, --output FILE
Output HTML file (default: input filename with .html extension)
-t TITLE, --title TITLE
Document title (default: filename without extension)
--theme {light,dark} Default theme (default: light)
--no-mermaid Disable Mermaid diagram support
--no-toc Disable table of contents generation
-q, --quiet Suppress output messages
-v, --version show program's version number and exit
๐ Mermaid Diagrams
The tool supports all Mermaid diagram types. Simply use fenced code blocks with mermaid language:
Flowchart
```mermaid
flowchart TD
A[Start] --> B{Is it working?}
B -->|Yes| C[Great!]
B -->|No| D[Debug]
D --> B
```
Sequence Diagram
```mermaid
sequenceDiagram
Alice->>Bob: Hello Bob!
Bob-->>Alice: Hi Alice!
```
Pie Chart
```mermaid
pie title Project Distribution
"Development" : 45
"Testing" : 25
"Documentation" : 15
"Other" : 15
```
Gantt Chart
```mermaid
gantt
title Project Timeline
dateFormat YYYY-MM-DD
section Phase 1
Task 1 :a1, 2024-01-01, 30d
Task 2 :after a1, 20d
```
๐จ Syntax Highlighting
Code blocks are automatically highlighted with language detection:
```python
def hello_world():
print("Hello, World!")
```
```javascript
const greet = (name) => {
console.log(`Hello, ${name}!`);
};
```
Supported languages include: Python, JavaScript, TypeScript, Java, C, C++, Go, Rust, Ruby, PHP, SQL, HTML, CSS, JSON, YAML, Bash, and many more.
๐ Theme Support
The generated HTML includes both light and dark themes:
- Light Theme: Clean white background with blue accents
- Dark Theme: Dark slate background with softer colors
Users can toggle between themes using the switch in the header. The preference is saved in localStorage.
๐ Project Structure
mk2html/
โโโ mk2html.py # Main CLI tool
โโโ requirements.txt # Python dependencies
โโโ README.md # This file
โโโ SESSION.md # Development session log
โโโ sample.md # Sample markdown file
โโโ sample_with_mermaid.md # Sample with Mermaid diagrams
โโโ *.html # Generated output files
๐ง Dependencies
| Package | Version | Description |
|---|---|---|
| markdown | โฅ3.4.0 | Markdown parsing |
| Pygments | โฅ2.15.0 | Syntax highlighting (backup) |
External CDN Resources
The generated HTML loads these from CDN:
- Mermaid.js v10 - Diagram rendering
- Highlight.js v11.9 - Syntax highlighting
๐ Example
Convert the sample file:
python3 mk2html.py sample_with_mermaid.md -o demo.html --title "Demo Document"
Then open demo.html in your browser.
๐ค Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
๐ License
MIT License - feel free to use this tool for any purpose.
๐ Acknowledgments
- Python-Markdown for Markdown parsing
- Mermaid.js for diagram rendering
- Highlight.js for syntax highlighting
- Design inspired by modern documentation sites
Made with โค๏ธ by Kinshuk
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mk2html-1.3.0.tar.gz.
File metadata
- Download URL: mk2html-1.3.0.tar.gz
- Upload date:
- Size: 22.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b938054dcf140cc5b9381704861dad246274deb583205be088ac0bf198329d3
|
|
| MD5 |
45a7deb92962514ea91f508f1b9cef7e
|
|
| BLAKE2b-256 |
2344e02b18369f08b583617ec3b6125acfa2c9db44eec5512e807903732548f0
|
File details
Details for the file mk2html-1.3.0-py3-none-any.whl.
File metadata
- Download URL: mk2html-1.3.0-py3-none-any.whl
- Upload date:
- Size: 33.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e844c932dc037a0247235c01dd941c5ee9195c11ff99052c59a7545e3dfa48d9
|
|
| MD5 |
1dd46c2a034373762acb08f227ec2a93
|
|
| BLAKE2b-256 |
159713a66de3afa172341012b21773ac5a10521b8b82a9c874aa23335b7c4b9a
|