simple_markdown v0.7.0 SimpleMarkdown

Converts markdown into the specified rendered output.

While this step is completely optional, if you need to configure any rules 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 type attribute()
attribute() :: %atom(){input: [attribute() | String.t()], option: any()}

Link to this section Functions

Link to this function ast_to_structs(ast)
ast_to_structs([Parsey.ast()]) :: [attribute() | String.t()]
ast_to_structs(Stream.t()) :: Stream.t()

Convert the AST into structs to allow for the rendering protocols to be applied to individual attributes.

Link to this function child_module!(parent, child)
child_module!(String.t() | atom(), String.t() | atom()) :: atom()

Create a child module relative to parent.

Link to this function convert(input, options \\ [])
convert(String.t(),
  parser: [Parsey.rule()],
  render: (Stream.t() | [attribute() | String.t()] -> String.t())
) :: String.t()
convert(String.t(),
  parser: [Parsey.rule()],
  render: (Stream.t() | [attribute() | String.t()] -> Stream.t())
) :: Stream.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.

Link to this function format_as_module(name)
format_as_module(String.t()) :: String.t()

Format a string to follow the module naming convention.