A markdown to HTML converter with LaTeX math support and beautiful styling
Project description
Markdown to HTML Converter with Math Support
A Python package that converts markdown text to HTML with LaTeX math support and beautiful styling.
Installation
pip install md2html-math
Usage
Command Line Interface
# Convert a markdown file to HTML (output will be in the same directory)
md2html-math /path/to/input.md
# Convert a markdown file to HTML with custom output path
md2html-math /path/to/input.md --output /path/to/output.html
# or
md2html-math /path/to/input.md -o /path/to/output.html
Python API
Converting Markdown Strings
from md2html.converter import markdown_to_html
# Basic usage
markdown_text = "# Hello, World!"
html = markdown_to_html(markdown_text)
print(html)
# Output: <h1>Hello, World!</h1>
# With LaTeX math
markdown_text = """
# Math Example
Inline math: $E = mc^2$
Block math:
$$
\\frac{n!}{k!(n-k)!} = \\binom{n}{k}
$$
"""
html = markdown_to_html(markdown_text)
print(html)
Converting Markdown Files
from md2html.converter import markdown_file_to_html
# Convert markdown file to HTML string
html = markdown_file_to_html("input.md")
print(html)
# Convert markdown file and save to HTML file
markdown_file_to_html("input.md", "output.html") # Will create output.html
markdown_file_to_html("input.md", "output") # Will create output.html
Features
- Beautiful, responsive HTML output with modern styling
- LaTeX math support:
- Inline math using
$...$or\(...\) - Block math using
$$...$$or\[...\] - Powered by KaTeX for fast rendering
- Inline math using
- Markdown features:
- Headers (#, ##, ###, etc.)
- Bold and italic text
- Lists (ordered and unordered)
- Links and images
- Code blocks with syntax highlighting
- Blockquotes
- Horizontal rules
- Tables
- Footnotes
- Table of contents
- And more!
- File conversion support:
- Convert markdown files to HTML strings
- Save HTML output to files
- Automatic .html extension handling
- UTF-8 encoding support
- Command line interface:
- Convert files from the command line
- Automatic output file generation
- Custom output path support
- Error handling and user feedback
Math Examples
Inline Math
The quadratic formula is $x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}$.
Block Math
The integral of a function is:
$$
\\int_{a}^{b} f(x) \\, dx = F(b) - F(a)
$$
Development
To set up the development environment:
# Clone the repository
git clone https://github.com/yourusername/md2html-math.git
cd md2html-math
# Create and activate a virtual environment
conda create -n md2html-math python=3.11
conda activate md2html-math
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
License
MIT License
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
md2html_math-0.1.0.tar.gz
(8.2 kB
view details)
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 md2html_math-0.1.0.tar.gz.
File metadata
- Download URL: md2html_math-0.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1902016982fc09de37f3f09e0a04e681710808384f5f41bfda9940295fecd80
|
|
| MD5 |
0350950590a6a312c7fc3de25715f1fe
|
|
| BLAKE2b-256 |
ea7b47882c580979008207cf12963cd372d906fc329635f671212e1961dbe861
|
File details
Details for the file md2html_math-0.1.0-py3-none-any.whl.
File metadata
- Download URL: md2html_math-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b92a611d52bf25a48fdcd9f7c7e25d049e120785a60e867b600b75b5e13442a8
|
|
| MD5 |
92f0024d94b14bb41c401edab86cec57
|
|
| BLAKE2b-256 |
1ebcd11133dc5ad016e0d4c2333abc35d0f980e2876d323485c46a74b33e633e
|