simple_markdown v0.5.4 SimpleMarkdown
Converts markdown into the specified rendered output.
When first using the library the first thing to do is usually to generate the base rule config.
$ mix simple_markdown.rules.new
And then importing the config in your config.exs:
import_config "simple_markdown_rules.exs"
This config can be customized as you see fit. With new rules added, and other rules removed or modified. Depending on the changes made this may require some additional steps for things to work the way you want. e.g. If you add or change the way a rule type fundamentally works, you’ll need to add or override the required rendering step for that type. Details for this can be found in renderer protocols.
Example
#config/simple_markdown_rules.exs
#add the following rule to our ruleset
lol: %{ match: ~r/\Alol/, rules: [] }
#lib/lol_renderer.ex
#add a renderer for the HTML renderer for our "lol" rule
defimpl SimpleMarkdown.Renderer.HTML, for: SimpleMarkdown.Attribute.Lol do
def render(_), do: "<img src=\"lolcat.jpg\">"
end
#usage:
SimpleMarkdown.convert("#lol") #=> "<h1><img src=\"lolcat.jpg\"></h1>"
Additionally new renderers can be created. How these new renderers should
be implemented is left up to you depending on how you’ll provide input.
If you use the standard convert/2
then the input will
be parsed, then the AST will be converted to these structs, and then
that will be passed to your renderer. Alternatively you may call
SimpleMarkdown.Parser.parse/1
directly and then manipulate that AST
how you see fit, and pass that to your renderer.
Link to this section Summary
Functions
Convert the AST into structs to allow for the rendering protocols to be applied to individual attributes
Create a child module relative to parent
Convert the text input into the rendered output. The default parser used is the one provided in the rules config, and the default renderer is the HTML renderer
Format a string to follow the module naming convention
Link to this section Types
Link to this section Functions
ast_to_structs([Parsey.ast()]) :: [attribute() | String.t()]
Convert the AST into structs to allow for the rendering protocols to be applied to individual attributes.
Create a child module relative to parent.
convert(String.t(), parser: [Parsey.rule()], render: ([SimpleMarkdown.attribute() | String.t()] -> String.t()) ) :: String.t()
Convert the text input into the rendered output. The default parser used is the one provided in the rules config, and the default renderer is the HTML renderer.
Format a string to follow the module naming convention.