simple_markdown v0.8.1 SimpleMarkdown.Renderer.HTML.AST protocol
A renderer protocol for HTML AST.
Individual rule renderers can be overriden or new ones may be
added. Rule types follow the format of structs defined under
SimpleMarkdown.Attribute.*
. e.g. If there is a rule with the
name :header
, to provide a rendering implementation for that
rule, you would specify for: SimpleMarkdown.Attribute.Header
.
Rules then consist of a Map with an input
field, and an optional
option
field. See SimpleMarkdown.attribute/0
.
HTML vs AST
The AST format (SimpleMarkdown.Renderer.HTML.Utilities.ast/0
) provides a
more flexible general purpose way of structuring HTML. While HTML provides a
more cumbersome by explicit way of structuring the rendered HTML.
When there is no implementation for a certain rule it will fallback to the
SimpleMarkdown.Renderer.HTML
renderer (if one exists) and will convert that
HTML to AST using SimpleMarkdown.Renderer.HTML.Utilities.html_to_ast/2
. So
you only need to maintain one set of implementations to cover all HTML renderers.
Example
defimpl SimpleMarkdown.Renderer.HTML.AST, for: SimpleMarkdown.Attribute.Header do
def render(%{ input: input, option: size }), do: { "h#{size}", [], SimpleMarkdown.Renderer.HTML.AST.render(input) }
end
Link to this section Summary
Functions
Render the parsed markdown as HTML AST.
Link to this section Types
Specs
t() :: term()
Link to this section Functions
render(ast)
Specs
render( Stream.t() | [SimpleMarkdown.attribute() | String.t()] | SimpleMarkdown.attribute() | String.t() ) :: SimpleMarkdown.Renderer.HTML.Utilities.ast()
Render the parsed markdown as HTML AST.