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.4.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.4-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: md2html_math-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 8faf1defd16ce6d009f53f15a44f85a25b2b8f8ea8f7a492a3905d605302e5c0
MD5 4d099f9c818174bc20988fa85960550a
BLAKE2b-256 8fcf9b6aca7bc60f10073a4d92e26f68af4a2ec1b24875f4eb860b49b57a6c1e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: md2html_math-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1a59478f7ddaf7e48ba749fd049c6c258d4f0ae8ca388639170f814242518f64
MD5 d836fae788c31c5a6c3f34bae121340b
BLAKE2b-256 2cd21d829c95175ac8b36ea50cdf2149e7dd87e135ce12349700a56480631582

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