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.5.tar.gz (10.1 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.5-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: md2html_math-0.1.5.tar.gz
  • Upload date:
  • Size: 10.1 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.5.tar.gz
Algorithm Hash digest
SHA256 acefa1ce7a4143053e6746fb02726b4246f465ccab3c8d74bac4393f13587fd6
MD5 e2d8ab821fa75ea90232351227a1e74c
BLAKE2b-256 7c69a61391de0a21f43b03d29a044381eae5d4e8d23d11bf152184c6b65f0847

See more details on using hashes here.

File details

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

File metadata

  • Download URL: md2html_math-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 10.6 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0799a1440bd804d8dafa0eeaf7916ae12d4bf6e8058c83838603474bbae42b30
MD5 c03db0cced87c91af3f1464c8f419dea
BLAKE2b-256 be5ce42c2a1d7a28298dc60cb042dde814e33985905758973729a21aeea707fd

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