Skip to main content

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.

Tests PyPI version Python License

โœจ 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:

๐Ÿ“ 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


Made with โค๏ธ by Kinshuk

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mk2html-1.3.0.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mk2html-1.3.0-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

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

Hashes for mk2html-1.3.0.tar.gz
Algorithm Hash digest
SHA256 0b938054dcf140cc5b9381704861dad246274deb583205be088ac0bf198329d3
MD5 45a7deb92962514ea91f508f1b9cef7e
BLAKE2b-256 2344e02b18369f08b583617ec3b6125acfa2c9db44eec5512e807903732548f0

See more details on using hashes here.

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

Hashes for mk2html-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e844c932dc037a0247235c01dd941c5ee9195c11ff99052c59a7545e3dfa48d9
MD5 1dd46c2a034373762acb08f227ec2a93
BLAKE2b-256 159713a66de3afa172341012b21773ac5a10521b8b82a9c874aa23335b7c4b9a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page