Packages

**The extended, configurable markdown-like syntax parser, that produces an AST.** Supports the full set of `markdown`, plus extensions (custom markup with a bit of elixir code to handle parsing.) The AST produced is understandable by [`XmlBuilder`](https://github.com/joshnuss/xml_builder).

Current section

Files

Jump to
markright lib markright parsers article.ex
Raw

lib/markright/parsers/article.ex

defmodule Markright.Parsers.Article do
@moduledoc ~S"""
Parses the whole text, producing a single article item.
## Examples
iex> cont = "![http://example.com Hello my] lovely world!" |> Markright.Parsers.Article.to_ast
...> cont.ast
{:article, %{},
[{:p, %{}, [{:img, %{src: "http://example.com", alt: "Hello my"}, nil}, " lovely world!"]}]}
"""
##############################################################################
@behaviour Markright.Parser
##############################################################################
require Logger
##############################################################################
use Markright.Continuation
##############################################################################
def to_ast(input, fun \\ nil, opts \\ %{})
when is_binary(input) and (is_nil(fun) or is_function(fun)) and is_map(opts) do
Markright.Utils.continuation(astify(input, fun), {:article, opts, fun})
end
##############################################################################
defp astify(input, fun, acc \\ []) do
case Markright.Parsers.Generic.to_ast(@splitter <> input, fun) do
%C{ast: "", tail: ""} -> %C{ast: acc}
%C{ast: ast, tail: ""} -> %C{ast: acc ++ [ast]}
%C{ast: "", tail: tail} -> astify(tail, fun, acc)
%C{ast: ast, tail: tail} -> astify(tail, fun, acc ++ [ast])
end
end
end