Surface.Code.Formatter (SurfaceFormatter v0.2.0) View Source
Functions for formatting Surface code snippets.
Link to this section Summary
Types
A parsed HTML/Component attribute name and value
The value of a parsed HTML/Component attribute
:line_length
- Maximum line length before wrapping opening tags:indent
- Starting indentation depth depending on the context of the ~H sigil
A node output by Surface.Compiler.Parser.parse/1
The name of an HTML/Surface tag, such as div
, ListItem
, or #Markdown
Context of a section of whitespace. This allows the formatter to decide things such as how much indentation to provide after a newline.
Functions
Given a list of formatter_node/0
, return a formatted string of Surface code
Given a string of Surface code, return a list of surface nodes including special whitespace nodes that enable formatting.
Deeply traverse parsed Surface nodes, converting string nodes into a list of
strings and :whitespace
atoms.
Link to this section Types
Specs
attribute() :: {name :: String.t(), attribute_value(), term()}
A parsed HTML/Component attribute name and value
Specs
attribute_value() :: integer() | boolean() | String.t() | {:attribute_expr, interpolated_expression :: String.t(), term()} | [String.t()]
The value of a parsed HTML/Component attribute
Specs
formatter_node() :: surface_node() | {:whitespace, whitespace_context()}
A node output by parse/1
. Simply a transformation of the output of
parse/1
, with contextualized whitespace nodes parsed out of the string
nodes.
Specs
:line_length
- Maximum line length before wrapping opening tags:indent
- Starting indentation depth depending on the context of the ~H sigil
Specs
surface_node() :: String.t() | {:interpolation, String.t(), map()} | {tag(), [attribute()], [surface_node()], map()}
A node output by Surface.Compiler.Parser.parse/1
Specs
tag() :: String.t()
The name of an HTML/Surface tag, such as div
, ListItem
, or #Markdown
Specs
whitespace_context() :: :before_child | :before_closing_tag | :before_whitespace | :indent
Context of a section of whitespace. This allows the formatter to decide things such as how much indentation to provide after a newline.
Link to this section Functions
Specs
format([formatter_node()], [option()]) :: String.t()
Given a list of formatter_node/0
, return a formatted string of Surface code
Specs
parse(String.t()) :: [formatter_node()]
Given a string of Surface code, return a list of surface nodes including special whitespace nodes that enable formatting.
Specs
parse_whitespace(surface_node()) :: [surface_node() | :whitespace]
Deeply traverse parsed Surface nodes, converting string nodes into a list of
strings and :whitespace
atoms.