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 blockquote.ex
Raw

lib/markright/parsers/blockquote.ex

defmodule Markright.Parsers.Blockquote do
@moduledoc ~S"""
Parses the input for the blockquote block.
## Examples
iex> input = "Hello
...> — _world_!
...>
...> Other text.
...> "
iex> Markright.Parsers.Blockquote.to_ast(input)
%Markright.Continuation{
ast: {:blockquote, %{}, [
"Hello\n — ", {:em, %{}, "world"}, "!"]},
tail: " Other text.\n "}
"""
##############################################################################
@behaviour Markright.Parser
##############################################################################
@max_indent Markright.Syntax.indent()
##############################################################################
require Logger
##############################################################################
use Markright.Continuation
##############################################################################
def to_ast(input, %Plume{} = plume \\ %Plume{}) when is_binary(input) do
with %Plume{ast: ast, tail: tail} <- astify(input, plume),
plume <- plume |> Plume.untail!,
%Plume{ast: block, tail: ""} <- Markright.Parsers.Generic.to_ast(ast, plume),
do: Markright.Utils.continuation(
%Plume{plume | ast: block, tail: tail}, {:blockquote, %{}})
end
##############################################################################
@spec astify(String.t, Markright.Continuation.t) :: Markright.Continuation.t
defp astify(part, plume)
##############################################################################
defp astify(<<
unquote(@splitter) :: binary,
rest :: binary
>>, %Plume{} = plume),
do: Plume.astail!(plume, rest)
Enum.each(0..@max_indent-1, fn i ->
indent = String.duplicate(" ", i)
{tag, handler} = Markright.Syntax.block()[:blockquote] # FIXME!!!
defp astify(<<
@unix_newline :: binary,
unquote(indent) :: binary,
unquote(tag) :: binary,
rest :: binary
>>, %Plume{} = plume) do
astify(" " <> rest, plume)
end
end)
defp astify(<<letter :: binary-size(1), rest :: binary>>, %Plume{} = plume),
do: astify(rest, Plume.tail!(plume, letter))
defp astify("", %Plume{} = plume),
do: Plume.astail!(plume, "")
##############################################################################
end