View Source Md.Parser behaviour (md v0.7.6)

Interface to implement for the custopm parsers.

Custom parsers might be used in syntax declaration when the generic functionality is not enough.

Let’s consider one needs a specific handling of links with titles.

The generic engine does not support it, so one would need to implement a custom parser and instruct Md.Parser to use it with:

# config/prod.exs

config :md, syntax: %{
  custom: %{
    {"![", MyApp.Parsers.Img},
    ...
  }
}

Once the original parser would meet the "![" binary, it’d call MyApp.Parsers.Img.parse/2. The latter must proceed until the tag is closed and return the remainder and the updated state as a tuple.

Link to this section Summary

Types

The type to be used in all the intermediate states of parsing.

Callbacks

Takes a not parsed yet input and the state, returns the updated remainder and state.

Link to this section Types

@type parsing_stage() :: {binary(), Md.Listener.state()}

The type to be used in all the intermediate states of parsing.

The first element iof the tuple is the continuation (not parsed yet input,) and the latter is the current state.

Link to this section Callbacks

@callback parse(binary(), Md.Listener.state()) :: parsing_stage()

Takes a not parsed yet input and the state, returns the updated remainder and state.

Link to this section Functions

Link to this function

generate(input, parser \\ DefaultParser, options \\ [])

View Source