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.3.tar.gz (9.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.3-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: md2html_math-0.1.3.tar.gz
  • Upload date:
  • Size: 9.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.3.tar.gz
Algorithm Hash digest
SHA256 089290d46fcb3fc2585a0e18b0901df49f246eff978f6d4d57dc308dc97d5618
MD5 25c6da3d6f2338fbd42b251a4586e973
BLAKE2b-256 6e53b0cbe4d03eba356ec2357cd7f03148445fa49ebf5779854e68939375543f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: md2html_math-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.7 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b73ea8b34851f0c263001082782606782195d729a5c5ec7434cb7db833530d32
MD5 3e2cc5ba3aca62db50773ccd898a9a2a
BLAKE2b-256 f0d1235503c36c6ee392801e115dc558f53b7b2fe680a290a0eacf7c1f003d44

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