Quickstart

Parse your first Markdown document in 2 minutes

1 min read 296 words

Parse Markdown to a typed AST and render to HTML in 2 minutes.

Prerequisites

Before You Start

0/2 complete

Step 1: Parse Markdown

from patitas import parse

source = """
# Welcome

This is **bold** and *italic* text.

- Item one
- Item two
"""

doc = parse(source)

Step 2: Explore the AST

# doc is a Document with children (tuple of Block nodes)
print(len(doc.children))  # 3 (Heading, Paragraph, List)

# Access the heading
heading = doc.children[0]
print(heading.level)  # 1
print(heading.children)  # (Text("Welcome"),)

# Access the paragraph
para = doc.children[1]
print(para.children)  # (Text, Strong, Text, Emphasis, Text)

Step 3: Render to HTML

from patitas import render

html = render(doc, source=source)
print(html)

Output:

<h1>Welcome</h1>
<p>This is <strong>bold</strong> and <em>italic</em> text.</p>
<ul>
<li>Item one</li>
<li>Item two</li>
</ul>

⚠️ render()does not sanitize output. It is CommonMark-compliant and passes raw HTML andjavascript:/data:URLs through verbatim. For untrusted content, sanitize the AST first (or render to plain text withrender_llm()).

Step 4: Sanitize Untrusted Input

When rendering Markdown you did not write, strip HTML and disallowed URL schemes before rendering to HTML:

from patitas import parse, render, sanitize
from patitas.sanitize import web_safe

doc = parse(untrusted_markdown)
html = render(sanitize(doc, policy=web_safe))

See LLM Safety for sanitization policies (web_safe, llm_safe, strict) and the render_llm()pipeline.

Step 5: All-in-One

For simple use cases, use theMarkdownclass:

from patitas import Markdown

md = Markdown()
html = md("# Hello **World**")
print(html)
# <h1>Hello <strong>World</strong></h1>

Next Steps

  • [Syntax Guide] — Learn all Markdown syntax
  • API Reference — Full API documentation
  • Architecture — How the parser works