Markdown content parser for the Prosody content analysis library.
This module parses markdown to AST using MDEx and extracts linearized content blocks
for accurate analysis that reflects rendered content rather than raw markdown. Code
blocks are tagged as type: :code so that alternative content analysis is possible.
Summary
Functions
Parse Markdown content (from String.t/0 or MDEx.Document.t/0) into a
Prosody.block/0 list. Returns {:ok, blocks} or {:error, reason}.
Parse Markdown content (from String.t/0 or MDEx.Document.t/0) into
a Prosody.block/0 list. Returns blocks or raises an error.
Functions
Parse Markdown content (from String.t/0 or MDEx.Document.t/0) into a
Prosody.block/0 list. Returns {:ok, blocks} or {:error, reason}.
Options
Options are ignored when the content is provided as MDEx.Document.t/0.
:strip_frontmatter(default:true): Whether to strip YAML frontmatter.- Other options are passed to MDEx for parsing configuration, including
:plugins.
Examples
iex> Prosody.MDExParser.parse("Hello **world**!")
{:ok, [
%{type: :text, content: "Hello ", language: nil, metadata: %{}},
%{type: :text, content: "world", language: nil, metadata: %{}},
%{type: :text, content: "!", language: nil, metadata: %{}}
]}
iex> Prosody.MDExParser.parse("Text\n\n```elixir\ndef hello, do: :ok\n```")
{:ok, [
%{type: :text, content: "Text", language: nil, metadata: %{}},
%{type: :code, content: "def hello, do: :ok\n", language: "elixir", metadata: %{}}
]}
iex> document = MDEx.new(markdown: "# Hello")
iex> Prosody.MDExParser.parse(document)
{:ok, [%{type: :text, content: "Hello", language: nil, metadata: %{}}]}
Parse Markdown content (from String.t/0 or MDEx.Document.t/0) into
a Prosody.block/0 list. Returns blocks or raises an error.
Options
Options are ignored when the content is provided as MDEx.Document.t/0.
:strip_frontmatter(default:true): Whether to strip YAML frontmatter.- Other options are passed to MDEx for parsing configuration, including
:plugins.
Examples
iex> Prosody.MDExParser.parse!("Hello **world**!")
[
%{type: :text, content: "Hello ", language: nil, metadata: %{}},
%{type: :text, content: "world", language: nil, metadata: %{}},
%{type: :text, content: "!", language: nil, metadata: %{}}
]
iex> Prosody.MDExParser.parse!("Text\n\n```elixir\ndef hello, do: :ok\n```")
[
%{type: :text, content: "Text", language: nil, metadata: %{}},
%{type: :code, content: "def hello, do: :ok\n", language: "elixir", metadata: %{}}
]
iex> document = MDEx.new(markdown: "# Hello")
iex> Prosody.MDExParser.parse!(document)
[%{type: :text, content: "Hello", language: nil, metadata: %{}}]