Skip to content

Markdown API Reference

markdown

Markdown to HTML renderer — zero dependencies, stdlib only, Python 3.10+.

Part of zerodep: https://github.com/Oaklight/zerodep Copyright (c) 2026 Peng Ding. MIT License.

Drop-in replacement for mistune's mistune.html() for common Markdown.

Supports
  • ATX and Setext headings
  • Paragraphs, thematic breaks, hard line breaks
  • Emphasis (bold, italic, bold-italic)
  • Inline code and fenced/indented code blocks
  • Links (inline, reference, autolink) and images
  • Ordered and unordered lists with nesting
  • Block quotes with nesting
  • GFM tables with column alignment
  • GFM strikethrough (~~text~~)
  • GFM task lists (- [ ] / - [x])
  • GFM extended autolinks (bare URLs)
  • Backslash escapes
Does NOT implement
  • Raw HTML passthrough (escaped for safety)
  • Footnotes, definition lists, math/LaTeX

Example::

from markdown import render
render("# Hello\n\nThis is **bold**.")
# '<h1>Hello</h1>\n<p>This is <strong>bold</strong>.</p>\n'

render(text)

Convert Markdown text to HTML.

Parameters:

Name Type Description Default
text str

Markdown source string.

required

Returns:

Type Description
str

HTML string.

Source code in markdown/markdown.py
def render(text: str) -> str:
    """Convert Markdown text to HTML.

    Args:
        text: Markdown source string.

    Returns:
        HTML string.
    """
    # Normalize line endings
    text = text.replace("\r\n", "\n").replace("\r", "\n")

    # Split into lines
    lines = text.split("\n")

    # Remove trailing newline that produces empty last element
    if lines and lines[-1] == "":
        lines.pop()

    # First pass: collect reference link definitions
    ref_links = _collect_ref_links(lines)

    # Second pass: parse blocks
    return _parse_blocks(lines, ref_links)