GitHub-flavored Markdown to HTML Converter

1.21.3 · active · verified Thu Apr 16

gh-md-to-html is a feature-rich Python module and command-line interface for converting GitHub-flavored Markdown to HTML. It leverages GitHub's online API by default for conversion but also offers robust offline capabilities. The library extends basic Markdown conversion with features like GitHub-flavored CSS, formula support, advanced image caching and optimization, host-ready file placement, PDF conversion, emoji shortcode support, and Table of Contents generation. The current version is 1.21.3, with PyPI releases occurring on a feature-driven, irregular cadence, complemented by frequent internal 'test-releases' on GitHub.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to convert a Markdown string to an HTML file using the `main_workflow` function. It showcases basic GitHub-flavored Markdown features including headers, bold text, lists, and code blocks. For more complex use cases, such as converting local files, repository paths, or hyperlinks, or to leverage features like PDF export and offline conversion, consult the library's full documentation and optional arguments.

import os
from gh_md_to_html import main_workflow

markdown_content = """
# Hello, gh-md-to-html!

This is **GitHub-flavored Markdown** with $\LaTeX$ formulas.

- Feature 1
- Feature 2

```python
print('Code blocks are awesome!')
```
"""

# Convert markdown string to HTML and save to a file
output_html_file = 'output.html'
main_workflow(
    md_origin=markdown_content,
    origin_type='string',
    output_name=output_html_file,
    destination_directory='.'
)
print(f"Converted markdown saved to {output_html_file}")

# Example of printing directly to console (without saving to file)
# html_output_string = main_workflow(
#     md_origin=markdown_content,
#     origin_type='string',
#     output_name='print'
# )
# print(html_output_string)

view raw JSON →