Skip to main content

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
  • 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/marcoallanda01/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.2.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

md2html_math-0.1.2-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file md2html_math-0.1.2.tar.gz.

File metadata

  • Download URL: md2html_math-0.1.2.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

Hashes for md2html_math-0.1.2.tar.gz
Algorithm Hash digest
SHA256 43edc3d7a22dace4e57057ec0aeafe40f5d7f39b8ec256ac73ceacd50ff9b0bf
MD5 5c328f411946895f47cb5b5272d0be03
BLAKE2b-256 e2b87166912a000a5caa35f91bca6f735ae4041d7941ee1a120d249d1d987a36

See more details on using hashes here.

File details

Details for the file md2html_math-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: md2html_math-0.1.2-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

Hashes for md2html_math-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0e1382416d5c5ac84fde8ac80131f8a4fd4ec84e396d794dd4fc1a57c2e99079
MD5 985e8d69434b56edb7f3bb139923a1ee
BLAKE2b-256 f70ff85d653121fe84bd03f6d630a16dd72a4a6bf774e9e8063b43efd5a428d7

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