"], %{verbatim: true}}, "more text"], []}
```
--------------------------------
### Adding Attributes to Inline Code
Source: https://hexdocs.pm/earmark_parser/index.html
Shows how to add attributes, including language specification, to inline code elements using the IAL syntax.
```elixir
iex(32)> markdown = "`Enum.map`{:lang=elixir}"
...(32)> as_ast(markdown)
{:ok, [{"p", [], [{"code", [{"class", "inline"}, {"lang", "elixir"}], ["Enum.map"], %{line: 1}}], %{}}], []}
```
--------------------------------
### EarmarkParser.Options
Source: https://hexdocs.pm/earmark_parser/api-reference.html
Configuration options for EarmarkParser.
```APIDOC
## EarmarkParser.Options
### Description
Configuration options for EarmarkParser.
### Method
(Not specified, likely a function call)
### Endpoint
(Not applicable, likely a method within a library)
### Parameters
(Not specified)
### Request Example
(Not specified)
### Response
(Not specified)
```
--------------------------------
### Using reduce_with_end to process a list with custom logic
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.Enum.Ext.html
Demonstrates how to use `reduce_with_end` to process a list containing numbers and nils. The reducer function handles elements and a final :end signal to aggregate results.
```Elixir
reducer =
fn {:element, nil}, {partial, result} -> {[], [Enum.sum(partial)|result]}
{:element, val}, {partial, result} -> {[val|partial], result}
:end, {partial, result} -> [Enum.sum(partial)|result] |> Enum.reverse
end
[1, 2, nil, 4, 1, 0, nil, 3, 2, 2]
|> reduce_with_end({[], []}, reducer)
```
--------------------------------
### Annotate HTML elements
Source: https://hexdocs.pm/earmark_parser/index.html
Demonstrates adding annotations to verbatim HTML elements, both inline and block-level. The annotation is associated with the HTML tag in the AST.
```iex
iex(39)> as_ast("One Line // a span", annotations: "//")
{:ok, [{"span", [], ["One Line"], %{annotation: "// a span", verbatim: true}}], []}
```
```iex
iex(40)> [
...(40)> " : annotation",
...(40)> " text",
...(40)> "
: discarded"
...(40)> ] |> as_ast(annotations: " : ")
{:ok, [{"div", [], [" text"], %{annotation: " : annotation", verbatim: true}}], []}
```
--------------------------------
### Parsing List with Header
Source: https://hexdocs.pm/earmark_parser/index.html
Illustrates parsing a Markdown list item containing a header element.
```elixir
iex(27)> as_ast("1. # Breaking...")
{:ok, [{"ol", [], [{"li", [], ({"h1", [], ["Breaking..."], %{}}), %{}}], %{}}], []}
```
--------------------------------
### html_one_line_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches one-line HTML elements within the given content.
```APIDOC
## html_one_line_matches(content)
### Description
Matches one-line HTML elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### heading_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches heading elements within the given content.
```APIDOC
## heading_matches(content)
### Description
Matches heading elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### Escape IAL attributes
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Demonstrates how to escape IAL attributes if necessary, preventing them from being parsed as attributes.
```iex
iex(35)> markdown = "[link](url)\\{: .classy}"
...(35)> EarmarkParser.as_ast(markdown)
{:ok, [{"p", [], [{"a", [{"href", "url"}], ["link"], %{}}, "{: .classy}"], %{}}], []}
```
--------------------------------
### Parse GFM Tables (Enabled)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Enable GFM table parsing by setting `gfm_tables: true`. This correctly structures Markdown tables into AST nodes, including headers and cells with default left alignment.
```elixir
iex(13)> as_ast("a|b\n-|-\nc|d\n", gfm_tables: true)
{:ok,
[
{"table",
[],
[
{"thead", [], [{"tr", [], [{"th", [{"style", "text-align: left;"}], ["a"], %{}}, {"th", [{"style", "text-align: left;"}], ["b"], %{}}], %{}}], %{}},
{"tbody", [], [{"tr", [], [{"td", [{"style", "text-align: left;"}], ["c"], %{}}, {"td", [{"style", "text-align: left;"}], ["d"], %{}}], %{}}], %{}}
],
%{}
}
],
[]}
```
--------------------------------
### void_tag_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches void tag elements within the given content.
```APIDOC
## void_tag_matches(content)
### Description
Matches void tag elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### Adding Attributes to Header in List Item
Source: https://hexdocs.pm/earmark_parser/index.html
Demonstrates adding attributes to a header within a list item using the IAL syntax.
```elixir
iex(31)> markdown = ["- # Headline{:.warning}"]
...(31)> as_ast(markdown)
{:ok, [{"ul", [], [{"li", [], ({"h1", [{"class", "warning"}], ["Headline"], %{}}), %{}}], %{}}], []}
```
--------------------------------
### Parsing One-line HTML Link Tags
Source: https://hexdocs.pm/earmark_parser/index.html
Parses a simple HTML link tag within Markdown.
```elixir
iex(1)> EarmarkParser.as_ast(~s{link})
{:ok, ["a", ["href", "href"], ["link"], %{verbatim: true}}], []}
```
--------------------------------
### Parsing Multiple HTML Tags
Source: https://hexdocs.pm/earmark_parser/index.html
Illustrates parsing multiple distinct HTML tags, including self-closing and paired tags, as verbatim AST nodes.
```elixir
iex(22)> {:ok, ast, []} = EarmarkParser.as_ast(["", "better"])
...(22)> ast
[
{"stupid", [], [], %{verbatim: true}},
{"not", [], ["better"], %{verbatim: true}}]
```
--------------------------------
### Parse Sub/Sup HTML Elements (Disabled)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Without the `sub_sup` option enabled, subscript and superscript notations are treated as plain text.
```elixir
iex(9)> EarmarkParser.as_ast("H~2~O or a^n^ + b^n^ = c^n^")
{:ok, [{"p", [], ["H~2~O or a^n^ + b^n^ = c^n^"], %{}}], []}
```
--------------------------------
### ial_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches inline attribute list elements within the given content.
```APIDOC
## ial_matches(content)
### Description
Matches inline attribute list elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### id_def_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches ID definition elements within the given content.
```APIDOC
## id_def_matches(content)
### Description
Matches ID definition elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### EarmarkParser.as_ast
Source: https://hexdocs.pm/earmark_parser/api-reference.html
Provides the structure of the result obtained from the `as_ast` function.
```APIDOC
## EarmarkParser.as_ast
### Description
This is the structure of the result of `as_ast`.
### Method
(Not specified, likely a function call)
### Endpoint
(Not applicable, likely a method within a library)
### Parameters
(Not specified)
### Request Example
(Not specified)
### Response
(Not specified)
```
--------------------------------
### Parse Display Mathematical Expressions
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Enable math parsing with `math: true`. Display-style expressions enclosed in double dollar signs (`$$`) are parsed as `math-display` code.
```elixir
iex> EarmarkParser.as_ast("$$x = 1$$", math: true)
{:ok, [{"p", [], [{"code", [{"class", "math-display"}], ["x = 1"], %{line: 1}}], %{}}], []}
```
--------------------------------
### indent_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches indented elements within the given content.
```APIDOC
## indent_matches(content)
### Description
Matches indented elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### Parse Markdown Links (Old Style)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Parses the older style of Markdown reference-style links, including titles.
```elixir
iex(3)> EarmarkParser.as_ast("[foo]: /url \"title\"\n\n[foo]\n")
{:ok, [{"p", [], [{"a", [{"href", "/url"}, {"title", "title"}], ["foo"], %{}}], %{}}], []}
```
--------------------------------
### GFM Table Interpretation with `gfm_tables: true`
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Illustrates how to enable GitHub Flavored Markdown table parsing using `gfm_tables: true`. This option allows interpreting interior vertical bars as table separators when a separation line is present.
```markdown
Language|Rating
--------|------
Elixir | awesome
```
--------------------------------
### table_first_column_rgx()
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Provides the regular expression for matching the first column of a table.
```APIDOC
## table_first_column_rgx()
### Description
Provides the regular expression for matching the first column of a table.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### EarmarkParser.as_ast
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Converts a Markdown string into an Abstract Syntax Tree (AST). It can return success, AST, and deprecation messages, or an error with AST and error messages.
```APIDOC
## EarmarkParser.as_ast
### Description
Converts a Markdown string into an Abstract Syntax Tree (AST). It can return success, AST, and deprecation messages, or an error with AST and error messages.
### Function Signature
```elixir
EarmarkParser.as_ast(markdown)
EarmarkParser.as_ast(markdown, options)
```
### Parameters
#### markdown
- **markdown** (string) - The Markdown content to parse.
#### options
- **options** (keyword list) - Optional. A list of options to customize parsing behavior. See `EarmarkParser.Options` for details.
### Return Value
- `{:ok, ast, deprecation_messages}` on success.
- `{:error, ast, error_messages}` on error.
- `{status, ast, errors}` when options are provided.
### Examples
```elixir
{:ok, ast, []} = EarmarkParser.as_ast("# Hello")
{:ok, ast, messages} = EarmarkParser.as_ast("~~strikethrough~~", gfm_tables: true)
```
```
--------------------------------
### Annotation precedence in multi-line paragraphs
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
When annotating multiple lines in a paragraph, the first annotation takes precedence.
```iex
iex(38)> as_ast("hello %> annotated\nworld %> discarded", annotations: "%>\n")
{:ok, [{"p", [], ["hello \nworld "], %{annotation: "%> annotated"}}], []}
```
--------------------------------
### table_header_rgx()
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Provides the regular expression for matching table headers.
```APIDOC
## table_header_rgx()
### Description
Provides the regular expression for matching table headers.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### Ignore malformed IAL attributes
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Shows how malformed IAL attributes are ignored and warnings are issued when parsing Markdown.
```iex
iex(34)> [ "Some text", "{:hello}" ] |> Enum.join("\n") |> EarmarkParser.as_ast()
{:error, [{"p", [], ["Some text"], %{}}], [{:warning, 2,"Illegal attributes [\"hello\"] ignored in IAL"}]}
```
--------------------------------
### Parse Pure Links (Default)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
By default, EarmarkParser treats bare URLs as links. This behavior is controlled by the `pure_links` option.
```elixir
iex(5)> EarmarkParser.as_ast("https://github.com")
{:ok, [{"p", [], [{"a", [{"href", "https://github.com"}], ["https://github.com"], %{}}], %{}}], []}
```
--------------------------------
### EarmarkParser.LineScanner.Rgx
Source: https://hexdocs.pm/earmark_parser/api-reference.html
Exposes regular expressions used in the scanner, optimized for readability and performance.
```APIDOC
## EarmarkParser.LineScanner.Rgx
### Description
Exposes the regular expressions needed in the scanner in a more readable and optilized way by forcing them to be compiled at compile time in this module and then inlining them by means of exposed functions.
### Method
(Not specified, likely a function call)
### Endpoint
(Not applicable, likely a method within a library)
### Parameters
(Not specified)
### Request Example
(Not specified)
### Response
(Not specified)
```
--------------------------------
### numbered_list_item_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches numbered list item elements within the given content.
```APIDOC
## numbered_list_item_matches(content)
### Description
Matches numbered list item elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### Adding Attributes to Block Element (Same Line)
Source: https://hexdocs.pm/earmark_parser/index.html
Shows how to append attributes directly to the end of a block element's line using the Kramdown IAL syntax.
```elixir
iex(29)> markdown = ["# Headline{:.from-same-line}"]
...(29)> as_ast(markdown)
{:ok, [{"h1", [{"class", "from-same-line"}], ["Headline"], %{}}], []}
```
--------------------------------
### Parse Markdown to AST
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Use `as_ast/1` to parse markdown into an AST. The function can return success with AST and deprecation messages, or an error with AST and error messages.
```elixir
{:ok, ast, []} = EarmarkParser.as_ast(markdown)
{:ok, ast, deprecation_messages} = EarmarkParser.as_ast(markdown)
{:error, ast, error_messages} = EarmarkParser.as_ast(markdown)
```
--------------------------------
### Adding Attributes to Header in Blockquote
Source: https://hexdocs.pm/earmark_parser/index.html
Illustrates adding attributes to a header nested within a blockquote using the IAL syntax.
```elixir
iex(30)> markdown = ["> # Headline{:.warning}"]
...(30)> as_ast(markdown)
{:ok, [{"blockquote", [], [{"h1", [{"class", "warning"}], ["Headline"], %{}}], %{}}], []}
```
--------------------------------
### IAL-like strings not parsed in code blocks or text lines
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Illustrates that IAL-like strings are not parsed when they appear in code blocks or regular text lines.
```iex
iex(36)> markdown = "hello {:world}"
...(36)> EarmarkParser.as_ast(markdown)
{:ok, [{"p", [], ["hello {:world}"], %{}}], []}
```
--------------------------------
### html_comment_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches HTML comment elements within the given content.
```APIDOC
## html_comment_matches(content)
### Description
Matches HTML comment elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### Parse Autolinks
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Automatically converts URLs enclosed in angle brackets into clickable links.
```elixir
iex(4)> EarmarkParser.as_ast("")
{:ok, [{"p", [], [{"a", [{"href", "https://elixir-lang.com"}], ["https://elixir-lang.com"], %{}}], %{}}], []}
```
--------------------------------
### underline_ruler_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches underline ruler elements within the given content.
```APIDOC
## underline_ruler_matches(content)
### Description
Matches underline ruler elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### html_self_closing_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches HTML self-closing tag elements within the given content.
```APIDOC
## html_self_closing_matches(content)
### Description
Matches HTML self-closing tag elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### Parse Inline Mathematical Expressions
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Enable math parsing with `math: true`. Inline expressions enclosed in single dollar signs (`$`) are parsed as `math-inline` code.
```elixir
iex> EarmarkParser.as_ast("$x = 1$", math: true)
{:ok, [{"p", [], [{"code", [{"class", "math-inline"}], ["x = 1"], %{line: 1}}], %{}}], []}
```
--------------------------------
### EarmarkParser.Options Type Definition
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.Options.html
Defines the structure of the EarmarkParser.Options, detailing all available configuration fields and their types.
```elixir
@type t() :: %EarmarkParser.Options{
all: boolean(),
annotations: nil | binary(),
breaks: boolean(),
code_class_prefix: nil | binary(),
file: binary(),
footnote_offset: non_neg_integer(),
footnotes: boolean(),
gfm: boolean(),
gfm_tables: boolean(),
line: number(),
math: term(),
messages: MapSet.t(),
parse_inline: boolean(),
pedantic: boolean(),
pure_links: boolean(),
renderer: term(),
smartypants: boolean(),
sub_sup: boolean(),
timeout: nil | non_neg_integer(),
wikilinks: boolean()
}
```
--------------------------------
### Parsing Lists with Code Blocks
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Shows how EarmarkParser handles lists containing code blocks, specifically a fenced code block within a list item.
```iex
iex(25)> markdown = [
"* aa",
" ```",
"Second",
" ```" ]
" ```" ]
...(25)> as_ast(markdown)
{:ok, [{"ul", [], [{"li", [], ["aa", {"pre", [], [{"code", [], ["Second"], %{}}], %{}}], %{}}], %{}}], []}
```
--------------------------------
### html_close_tag_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches HTML close tag elements within the given content.
```APIDOC
## html_close_tag_matches(content)
### Description
Matches HTML close tag elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### Annotate block HTML elements
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html
Shows how to annotate block-level HTML elements. The annotation is applied to the outermost tag.
```iex
iex(40)> [
...(40)> " : annotation",
...(40)> " text",
...(40)> "
: discarded"
...(40)> ] |> as_ast(annotations: " : ")
{:ok, [{"div", [], [" text"], %{annotation: " : annotation", verbatim: true}}], []}
```
--------------------------------
### block_quote_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches block quote elements within the given content.
```APIDOC
## block_quote_matches(content)
### Description
Matches block quote elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```
--------------------------------
### star_ruler_matches(content)
Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html
Matches star ruler elements within the given content.
```APIDOC
## star_ruler_matches(content)
### Description
Matches star ruler elements within the given content.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
None
#### Response Example
None
```