simple_markdown v0.8.0 SimpleMarkdown.Renderer.HTML.Utilities

Convenient functions for working with HTML.

Link to this section Summary

Functions

Convert the HTML AST to HTML.

Convert the HTML to HTML AST.

Link to this section Types

Specs

ast() ::
  {tag :: String.Chars.t(), attrs :: [{String.Chars.t(), String.Chars.t()}],
   ast()}
  | [ast()]
  | String.t()
Link to this type

format(type)

Specs

format(type) :: {type, version()}

Specs

formats() :: format(:html) | format(:xhtml)

Specs

tag_list() :: [atom() | String.t()]

Specs

version() :: {major :: non_neg_integer(), minor :: non_neg_integer()}

Link to this section Functions

Link to this function

ast_to_html(ast, opts \\ [])

Specs

ast_to_html(ast(), keyword()) :: IO.chardata()

Convert the HTML AST to HTML.

The conversion behaviour can be modified by setting the opts parameter with any of the following:

  • :format - To control the HTML format. This takes one of the valid formats/0. By default this is set to generate HTML5 code ({ :html, { 5, 0 } }).
  • :void_elements - To customise which elements are void elements (do not contain content). This takes a tag_list/0. By default this is set to the list of tags returned by void_elements/0.
  • :raw_text_elements - To customise which elements are raw text elements (do not encode their content nor contain nested nodes). This takes a tag_list/0. By default this is set to the list of tags returned by raw_text_elements/0.

Example

iex> SimpleMarkdown.Renderer.HTML.Utilities.ast_to_html({ :p, [], "hello" }) |> IO.chardata_to_string
"<p>hello</p>"
Link to this function

html_to_ast(html, opts \\ [])

Specs

html_to_ast(IO.chardata(), keyword()) :: ast()

Convert the HTML to HTML AST.

The parsing behaviour can be modified by setting the opts parameter with any of the following:

  • :void_elements - To customise which elements are void elements (do not contain content). This takes a tag_list/0. By default this is set to the list of tags returned by void_elements/0.
  • :raw_text_elements - To customise which elements are raw text elements (do not encode their content nor contain nested nodes). This takes a tag_list/0. By default this is set to the list of tags returned by raw_text_elements/0.

Example

iex> SimpleMarkdown.Renderer.HTML.Utilities.html_to_ast("<p>hello</p>")
{ "p", [], "hello" }
Link to this function

raw_text_elements()

Specs

raw_text_elements() :: tag_list()

A list of raw text elements.

Link to this function

void_elements()

Specs

void_elements() :: tag_list()

A list of void elements.