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.
A list of raw text elements.
A list of void elements.
Link to this section Types
Link to this type
ast()
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()}
Link to this type
formats()
Specs
Link to this type
tag_list()
Specs
Link to this type
version()
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 validformats/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 atag_list/0
. By default this is set to the list of tags returned byvoid_elements/0
.:raw_text_elements
- To customise which elements are raw text elements (do not encode their content nor contain nested nodes). This takes atag_list/0
. By default this is set to the list of tags returned byraw_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 atag_list/0
. By default this is set to the list of tags returned byvoid_elements/0
.:raw_text_elements
- To customise which elements are raw text elements (do not encode their content nor contain nested nodes). This takes atag_list/0
. By default this is set to the list of tags returned byraw_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.