### IAL Attribute Syntax Examples Source: https://hexdocs.pm/earmark_parser/index.html Provides examples of the Kramdown IAL syntax for adding class names, IDs, and key-value attributes to block elements. ```markdown # Warning {: .red} Do not turn off the engine if you are at altitude. {: .boxed #warning spellcheck="true"} ``` -------------------------------- ### Normalizing EarmarkParser Options Source: https://hexdocs.pm/earmark_parser/EarmarkParser.Options.html Demonstrates how to use the `normalize/1` function to prepare options before passing them to EarmarkParser API functions. This example shows setting the `annotations` option. ```elixir iex(1)> options = normalize(annotations: "%%") ...(1)> options.annotations ~r{\A(.*)(%%.*)} ``` -------------------------------- ### Parsing HTML Comments Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Demonstrates how HTML comments are recognized if they start a line, parsed until `-->`, and how subsequent text is handled. ```iex iex(24)> EarmarkParser.as_ast(" text -->\nafter") {:ok, [{:comment, [], [" Comment", "comment line", "comment "], %{comment: true}}, {"p", [], ["after"], %{}}], []} ``` -------------------------------- ### html_comment_start_matches(content) Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html Matches the start of HTML comment elements within the given content. ```APIDOC ## html_comment_start_matches(content) ### Description Matches the start of 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 ``` -------------------------------- ### Table Parsing with Alignment and Vertical Bars Source: https://hexdocs.pm/earmark_parser/index.html Shows a basic table structure with column alignment specified using colons. This example also demonstrates tables with leading and trailing vertical bars. ```markdown State | Abbrev | Capital ----: | :----: | ------- Texas | TX | Austin Maine | ME | Augusta ``` ```markdown | State | Abbrev | Capital | | ----: | :----: | ------- | | Texas | TX | Austin | | Maine | ME | Augusta | ``` -------------------------------- ### Markdown Table with Alignment Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Example of a Markdown table with explicit column alignment specified using colons. This is a standard Markdown table format. ```markdown State | Abbrev | Capital ----: | :----: | ------- Texas | TX | Austin Maine | ME | Augusta ``` -------------------------------- ### Enabling Hard Linebreaks Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Demonstrates how to enable hard linebreaks in EarmarkParser by setting `breaks: true`. The example shows a list item with internal newlines rendered with `
` tags in the AST. ```elixir iex(18)> ["* a"," b", "c"] ...(18)> |> as_ast(breaks: true) {:ok, [{"ul", [], [{"li", [], ["a", {"br", [], [], %{}}, "b", {"br", [], [], %{}}, "c"], %{}}], %{}}], []} ``` -------------------------------- ### Get EarmarkParser Version Source: https://hexdocs.pm/earmark_parser/index.html Retrieves the current hex version of the EarmarkParser application. This is a convenience function for use in interactive sessions (iex). ```elixir version() ``` -------------------------------- ### Hard Linebreaks Disabled by Default Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Illustrates that hard linebreaks are disabled by default in EarmarkParser. The example shows a list item with internal newlines rendered as a single line in the AST. ```elixir iex(17)> ["* a"," b", "c"] ...(17)> |> as_ast() {:ok, [{"ul", [], [{"li", [], ["a\nb\nc"], %{}}], %{}}], []} ``` -------------------------------- ### Enabling and Rendering Footnotes Source: https://hexdocs.pm/earmark_parser/index.html Demonstrates how to enable footnotes using `footnotes: true` and shows the resulting AST for a markdown string with footnote definitions and references. Unreferenced definitions are not rendered. ```elixir # iex(16)> markdown = [ # ...(16)> "My reference[^to_footnote]", # ...(16)> "", # ...(16)> "[^1]: I am not rendered", # ...(16)> "[^to_footnote]: Important information" # ...(16)> ] # ...(16)> {:ok, ast, []} = as_ast(markdown, footnotes: true) # ...(16)> ast # [ # {"p", [], ["My reference", # {"a", # [{"href", "#fn:to_footnote"}, {"id", "fnref:to_footnote"}, {"class", "footnote"}, {"title", "see footnote"}], # ["to_footnote"], %{}} # ], %{}}, # {"div", # [{"class", "footnotes"}], # [{"hr", [], [], %{}}], # ["ol", [], # [ # {"li", [{"id", "fn:to_footnote"}], # [ # {"a", [{"title", "return to article"}, {"class", "reversefootnote"}, {"href", "#fnref:to_footnote"}], ["↩"], %{}}, # {"p", [], ["Important information"], %{}} # ], %{}} # ], # %{}}], # %{}} # ] ``` -------------------------------- ### Enabling All Disabled Options Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Shows how to enable all options that are disabled by default using `all: true`. This includes features like superscript, subscript, and wikilinks. ```elixir iex(19)> [ ...(19)> "a^n^", ...(19)> "b~2~", ...(19)> "[[wikilink]]"] ...(19)> |> as_ast(all: true) {:ok, [ {"p", [], ["a", {"sup", [], ["n"], %{}}, {"br", [], [], %{}}, "b", {"sub", [], ["2"], %{}}, {"br", [], [], %{}}, {"a", [{"href", "wikilink"}], ["wikilink"], %{wikilink: true}}], %{}} ], []} ``` -------------------------------- ### EarmarkParser.as_ast with Options Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Demonstrates using the `as_ast/2` function with various options to control parsing behavior, such as enabling pure links, wikilinks, sub/sup elements, mathematical expressions, and GFM tables. ```APIDOC ## EarmarkParser.as_ast with Options ### Description This section details how to use the `as_ast/2` function with various options to customize the Markdown parsing process. Options can enable or disable specific features like pure links, wikilinks, sub/sup HTML elements, mathematical expressions, and GitHub Flavored Markdown (GFM) extensions. ### Supported Options and Examples #### Pure Links (enabled by default) ```elixir # Default behavior EarmarkParser.as_ast("https://github.com") # => {:ok, [{"p", [], [{"a", [{"href", "https://github.com"}], ["https://github.com"], %{}}], %{}}], []} # Deactivated EarmarkParser.as_ast("https://github.com", pure_links: false) # => {:ok, [{"p", [], ["https://github.com"], %{}}], []} ``` #### Wikilinks (disabled by default) ```elixir # Disabled EarmarkParser.as_ast("[[page]]") # => {:ok, [{"p", [], ["[[page]]"], %{}}], []} # Enabled EarmarkParser.as_ast("[[page]]", wikilinks: true) # => {:ok, [{"p", [], [{"a", [{"href", "page"}], ["page"], %{wikilink: true}}], %{}}], []} ``` #### Sub and Sup HTML Elements (disabled by default) ```elixir # Disabled 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^"], %{}}], []} # Enabled EarmarkParser.as_ast("H~2~O or a^n^ + b^n^ = c^n^", sub_sup: true) # => {:ok, [{"p", [], ["H", {"sub", [], ["2"], %{}}, "O or a", {"sup", [], ["n"], %{}}, " + b", {"sup", [], ["n"], %{}}, " = c", {"sup", [], ["n"], %{}}], %{}}], []} ``` #### Mathematical Expressions (disabled by default) ##### Inline Expressions ```elixir EarmarkParser.as_ast("$x = 1$", math: true) # => {:ok, [{"p", [], [{"code", [{"class", "math-inline"}], ["x = 1"], %{line: 1}}], %{}}], []} ``` ##### Block Expressions ```elixir EarmarkParser.as_ast("$$x = 1$$", math: true) # => {:ok, [{"p", [], [{"code", [{"class", "math-display"}], ["x = 1"], %{line: 1}}], %{}}], []} ``` #### Github Flavored Markdown (GFM) - Strike Through (enabled by default) ```elixir EarmarkParser.as_ast("~~hello~~") # => {:ok, [{"p", [], [{"del", [], ["hello"], %{}}], %{}}], []} ``` #### Github Flavored Markdown (GFM) - Tables (disabled by default) ```elixir # Disabled EarmarkParser.as_ast("a|b\n-|-\nc|d\n") # => {:ok, [{"p", [], ["a|b\n-|-\nc|d\n"], %{}}], []} # Enabled EarmarkParser.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"], %{}}], %{}}], %{}}], %{}} ``` ``` -------------------------------- ### Parsing Pure Links (Default) Source: https://hexdocs.pm/earmark_parser/index.html Demonstrates parsing of a URL as a link when the `pure_links` option is true (default). ```elixir iex(5)> EarmarkParser.as_ast("https://github.com") {:ok, ["p", [], ["a", ["href", "https://github.com"], ["https://github.com"], %{}}], []} ``` -------------------------------- ### Comment Markdown using annotations Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Illustrates using annotations to comment Markdown without cluttering the generated AST. This is useful for elements that do not yet support annotations. ```iex iex(41)> [ ...(41)> "# Headline --> first line", ...(41)> "- item1 --> a list item", ...(41)> "- item2 --> another list item", ...(41)> "", ...(41)> " --> do not go there" ...(41)> ] |> as_ast(annotations: "-->") {:ok, [ {"h1", [], ["Headline"], %{}}, {"ul", [], [{"li", [], ["item1 "], %{}}, {"li", [], ["item2 "], %{}}], %{}}, {"p", [], [{"a", [{"href", "http://somewhere/to/go"}], ["http://somewhere/to/go"], %{}}, " "], %{annotation: "--> do not go there"}} ], [] } ``` -------------------------------- ### Syntax Highlighting with Custom Prefixes Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Shows how to add custom class prefixes for syntax highlighters like Prism.js by configuring `code_class_prefix` in `EarmarkParser.Options`. Multiple prefixes can be specified. ```elixir iex(15)> [ ...(15)> "```elixir", ...(15)> " @tag :hello", ...(15)> "```" ...(15)> ] |> as_ast(%EarmarkParser.Options{code_class_prefix: "lang- language-"}) {:ok, [{"pre", [], [{"code", [{"class", "elixir lang-elixir language-elixir"}], [" @tag :hello"], %{}}], %{}}], []} ``` -------------------------------- ### Parsing Verbatim HTML Blocks Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Demonstrates parsing multi-line HTML blocks where the opening and closing tags are on separate lines. The `verbatim: true` option is used. ```iex iex(20)> lines = [ "
", "some
", "more text" ] ...(20)> EarmarkParser.as_ast(lines) {:ok, [{"div", [], ["", "some"], %{verbatim: true}}, "more text"], []} ``` -------------------------------- ### Parsing GFM Tables (Enabled) Source: https://hexdocs.pm/earmark_parser/index.html Shows how to enable GFM table parsing with the `gfm_tables: true` option. ```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"], %{}}], %{}}], %{}} ], %{} } ], []} ``` -------------------------------- ### Annotate paragraphs Source: https://hexdocs.pm/earmark_parser/index.html Shows how to add annotations to paragraphs using a specified annotation string. The first annotation takes precedence if multiple are present on different lines. ```iex iex(37)> as_ast("hello %> annotated", annotations: "%> ") {:ok, [{"p", [], ["hello "], %{annotation: "%> annotated"}}], []} ``` ```iex iex(38)> as_ast("hello %> annotated\nworld %> discarded", annotations: "%> ") {:ok, [{"p", [], ["hello \nworld "], %{annotation: "%> annotated"}}], []} ``` -------------------------------- ### Parse Markdown with Options Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Pass custom options to `as_ast/2` to modify parsing behavior. Refer to `EarmarkParser.Options` for available options. ```elixir {status, ast, errors} = EarmarkParser.as_ast(markdown, options) ``` -------------------------------- ### Syntax Highlighting with Default Classes Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Demonstrates how EarmarkParser renders fenced code blocks with language identifiers as class attributes on the `code` tag. This is useful for integrating with syntax highlighters. ```elixir iex(14)> [ ...(14)> "```elixir", ...(14)> " @tag :hello", ...(14)> "```" ...(14)> ] |> as_ast() {:ok, [{"pre", [], [{"code", [{"class", "elixir"}], [" @tag :hello"], %{}}], %{}}], []} ``` -------------------------------- ### Parsing Sub/Sup HTML Elements (Enabled) Source: https://hexdocs.pm/earmark_parser/index.html Shows how to enable sub/sup element parsing with the `sub_sup: true` option. ```elixir iex(10)> EarmarkParser.as_ast("H~2~O or a^n^ + b^n^ = c^n^", sub_sup: true) {:ok, ["p", [], ["H", {"sub", [], ["2"], %{}}, "O or a", {"sup", [], ["n"], %{}}, " + b", {"sup", [], ["n"], %{}}, " = c", {"sup", [], ["n"], %{}}], %{}}], []} ``` -------------------------------- ### Parsing Lists with Blockquotes Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Illustrates the support for immediate block content within list items, specifically a blockquote. ```iex iex(26)> as_ast("* > Nota Bene!") {:ok, [{"ul", [], [{"li", [], [{\ ``` -------------------------------- ### Parse Markdown Links (New Style) Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Parses standard Markdown links with a title and destination. ```elixir iex(2)> EarmarkParser.as_ast(~s{[title](destination)}) {:ok, [{"p", [], [{"a", [{"href", "destination"}], ["title"], %{}}], %{}}], []} ``` -------------------------------- ### Parse Sub/Sup HTML Elements (Enabled) Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Enable subscript and superscript parsing by setting `sub_sup: true`. This converts `~` for subscript and `^` for superscript into appropriate AST nodes. ```elixir iex(10)> EarmarkParser.as_ast("H~2~O or a^n^ + b^n^ = c^n^", sub_sup: true) {:ok, [{"p", [], ["H", {"sub", [], ["2"], %{}}, "O or a", {"sup", [], ["n"], %{}}, " + b", {"sup", [], ["n"], %{}}, " = c", {"sup", [], ["n"], %{}}], %{}}], []} ``` -------------------------------- ### Add IAL attributes to links or images Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Demonstrates how to add IAL attributes to generated links or images. Malformed attributes are ignored and warnings are issued. ```iex iex(33)> markdown = "[link](url) {: .classy}" ...(33)> EarmarkParser.as_ast(markdown) {:ok, [{"p", [], [{"a", [{"class", "classy"}, {"href", "url"}], ["link"], %{}}], %{}}], []} ``` -------------------------------- ### Parse Wikilinks (Enabled) Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Enable Wikilink parsing by setting the `wikilinks` option to `true`. This converts `[[page]]` into an internal link. ```elixir iex(8)> EarmarkParser.as_ast("[[page]]", wikilinks: true) {:ok, [{"p", [], [{"a", [{"href", "page"}], ["page"], %{wikilink: true}}], %{}}], []} ``` -------------------------------- ### Annotate single-line HTML elements Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Demonstrates annotating a single-line HTML element. The annotation is added to the meta map with the key `:annotation`. ```iex iex(39)> as_ast("One Line // a span", annotations: "//") {:ok, [{"span", [], ["One Line"], %{annotation: "// a span", verbatim: true}}], []} ``` -------------------------------- ### set_ext_underline_matches(content) Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html Matches setext heading underline elements within the given content. ```APIDOC ## set_ext_underline_matches(content) ### Description Matches setext heading underline 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 paragraphs Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Shows how to add annotations to paragraphs using the `annotations` option. The last occurrence of the annotation string in a line is used. ```iex iex(37)> as_ast("hello %> annotated", annotations: "%>\n") {:ok, [{"p", [], ["hello "], %{annotation: "%> annotated"}}], []} ``` -------------------------------- ### Parsing Multi-Line HTML Block Source: https://hexdocs.pm/earmark_parser/index.html Demonstrates parsing a multi-line HTML block enclosed by opening and closing tags. ```elixir iex(23)> {:ok, ast, []} = EarmarkParser.as_ast([ "", "world", ""]) ...(23)> ast [{"hello", [], ["world"], %{verbatim: true}}] ``` -------------------------------- ### Parse Wikilinks (Disabled by Default) Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Wikilinks are disabled by default. Parsing them without the option results in plain text. ```elixir iex(7)> EarmarkParser.as_ast("[[page]]") {:ok, [{"p", [], ["[[page]]"], %{}}], []} ``` -------------------------------- ### Parse GFM Tables (Disabled) Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html GFM tables are not enabled by default. Parsing them without the `gfm_tables` option treats the content as plain text. ```elixir iex(12)> as_ast("a|b\n-|-\nc|d\n") {:ok, [{"p", [], ["a|b\n-|-\nc|d\n"], %{}}], []} ``` -------------------------------- ### html_open_tag_matches(content) Source: https://hexdocs.pm/earmark_parser/EarmarkParser.LineScanner.Rgx.html Matches HTML open tag elements within the given content. ```APIDOC ## html_open_tag_matches(content) ### Description Matches HTML open 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 ``` -------------------------------- ### Enabling and Rendering Footnotes Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Demonstrates how to enable footnotes in EarmarkParser using the `footnotes: true` option. It shows the Markdown input with definitions and references, and the resulting AST with footnote links and definitions. ```elixir # iex(16)> markdown = [ # ...(16)> "My reference[^to_footnote]", # ...(16)> "", # ...(16)> "[^1]: I am not rendered", # ...(16)> "[^to_footnote]: Important information" # ...(16)> ] # ...(16)> {:ok, ast, []} = as_ast(markdown, footnotes: true) # ...(16)> ast # [ # {"p", [], ["My reference", # {"a", # [{"href", "#fn:to_footnote"}, {"id", "fnref:to_footnote"}, {"class", "footnote"}, {"title", "see footnote"}], # ["to_footnote"], %{}} # ], %{}}, # {"div", # [{"class", "footnotes"}], # [{"hr", [], [], %{}} , # {"ol", [], # [{"li", [{"id", "fn:to_footnote"}], # [{"a", [{"title", "return to article"}, {"class", "reversefootnote"}, {"href", "#fnref:to_footnote"}], ["↩"], %{}}, # {"p", [], ["Important information"], %{}}], %{}} # ], %{}}], # %{}} # ] ``` -------------------------------- ### Parsing GFM Tables (Disabled) Source: https://hexdocs.pm/earmark_parser/index.html Demonstrates that GFM tables are disabled by default and are parsed as plain text. ```elixir iex(12)> as_ast("a|b\n-|-\nc|d\n") {:ok, ["p", [], ["a|b\n-|-\nc|d\n"], %{}}], []} ``` -------------------------------- ### Parsing Single-Line Verbatim HTML Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Shows how a single line containing an HTML tag with attributes and content is parsed as a verbatim HTML node. ```iex iex(21)> EarmarkParser.as_ast(["spaniel"]) {:ok, [{"span", [{"class", "superspan"}], ["spaniel"], %{verbatim: true}}], []} ``` -------------------------------- ### Adding Attributes to Block Element (Next Line) Source: https://hexdocs.pm/earmark_parser/index.html Demonstrates using the Kramdown IAL syntax `{:.class}` on a line following a block element to add attributes to it. ```elixir iex(28)> markdown = ["# Headline", "{:.from-next-line}"] ...(28)> as_ast(markdown) {:ok, [{"h1", [{"class", "from-next-line"}], ["Headline"], %{}}], []} ``` -------------------------------- ### EarmarkParser.Enum.Ext Source: https://hexdocs.pm/earmark_parser/api-reference.html Contains extensions for Enum functions within EarmarkParser. ```APIDOC ## EarmarkParser.Enum.Ext ### Description Some extensions of Enum 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) ``` -------------------------------- ### Parse Markdown to AST Source: https://hexdocs.pm/earmark_parser/EarmarkParser.html Converts a markdown string into an Abstract Syntax Tree (AST). The AST is exposed in the spirit of Floki's. ```Elixir iex(42)> markdown = "My `code` is **best**" ...(42)> {:ok, ast, []} = EarmarkParser.as_ast(markdown) ...(42)> ast [{"p", [], ["My ", {"code", [{"class", "inline"}], ["code"], %{line: 1}}, " is ", {"strong", [], ["best"], %{}}], %{}}] ``` ```Elixir iex(43)> markdown = "```elixir\nIO.puts 42\n```" ...(43)> {:ok, ast, []} = EarmarkParser.as_ast(markdown, code_class_prefix: "lang-") ...(43)> ast [{"pre", [], [{"code", [{"class", "elixir lang-elixir"}], ["IO.puts 42"], %{}}], %{}}] ``` -------------------------------- ### Parsing Verbatim HTML Block Source: https://hexdocs.pm/earmark_parser/index.html Demonstrates parsing a multi-line HTML block where opening and closing tags define the block. The %{verbatim: true} flag indicates the HTML is treated as raw. ```elixir iex(20)> lines = [ "
", "some
", "more text" ] ...(20)> EarmarkParser.as_ast(lines) {:ok, [{"div", [], ["", "some"], %{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 ```