Sayfa.Markdown (Sayfa v0.5.0)

Copy Markdown View Source

Wrapper around MDEx for rendering Markdown to HTML.

Provides a consistent interface with {:ok, html} / {:error, reason} tuples and a bang variant that raises on error.

Supports optional syntax highlighting theme selection via the theme parameter.

Examples

iex> {:ok, html} = Sayfa.Markdown.render("# Hello")
iex> html =~ "Hello"
true

iex> Sayfa.Markdown.render!("**bold**")
"<p><strong>bold</strong></p>"

Summary

Functions

Renders a Markdown string to HTML.

Renders a Markdown string to HTML, raising on error.

Functions

render(markdown, theme \\ "github_light")

@spec render(String.t(), String.t()) :: {:ok, String.t()} | {:error, term()}

Renders a Markdown string to HTML.

Headings include anchor IDs for linking (e.g., <h1 id="hello">...</h1>). An optional theme string selects the syntax highlighting theme (default: "github_light").

Examples

iex> {:ok, html} = Sayfa.Markdown.render("# Hello")
iex> html =~ ~s(id="hello")
true

iex> Sayfa.Markdown.render("plain text")
{:ok, "<p>plain text</p>"}

render!(markdown, theme \\ "github_light")

@spec render!(String.t(), String.t()) :: String.t()

Renders a Markdown string to HTML, raising on error.

Examples

iex> html = Sayfa.Markdown.render!("# Hello")
iex> html =~ ~s(id="hello")
true