# `Prosody.MDExParser`
[🔗](https://github.com/halostatue/prosody/blob/v1.1.0/lib/prosody/mdex_parser.ex#L2)

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.

# `parse`
[🔗](https://github.com/halostatue/prosody/blob/v1.1.0/lib/prosody/mdex_parser.ex#L48)

Parse Markdown content (from `t:String.t/0` or `t:MDEx.Document.t/0`) into a
`t:Prosody.block/0` list. Returns `{:ok, blocks}` or `{:error, reason}`.

## Options

Options are ignored when the content is provided as `t: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

```elixir
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!`
[🔗](https://github.com/halostatue/prosody/blob/v1.1.0/lib/prosody/mdex_parser.ex#L101)

Parse Markdown content (from `t:String.t/0` or `t:MDEx.Document.t/0`) into
a `t:Prosody.block/0` list. Returns `blocks` or raises an error.

## Options

Options are ignored when the content is provided as `t: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

```elixir
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: %{}}]
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
