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
Current section
Files
lib/markright/parsers/img.ex
defmodule Markright.Parsers.Img do
@moduledoc ~S"""
Parses the input for the link.
## Examples
iex> "http://example.com Hello my] lovely world!" |> Markright.Parsers.Img.to_ast
%Markright.Continuation{ast: {:img,
%{alt: "Hello my", src: "http://example.com"}, nil},
tail: " lovely world!"}
"""
##############################################################################
@behaviour Markright.Parser
##############################################################################
def to_ast(input, fun \\ nil, opts \\ %{})
when is_binary(input) and (is_nil(fun) or is_function(fun)) and is_map(opts) do
with %Markright.Continuation{ast: first, tail: rest} <- Markright.Parsers.Word.to_ast(input),
%Markright.Continuation{ast: ast, tail: tail} <- astify(rest, fun) do
attrs = Map.merge(
opts, case ast do
[text, link] -> %{src: link, alt: first <> " " <> text}
text when is_binary(text) -> %{src: first, alt: text}
end)
Markright.Utils.continuation(:empty, %Markright.Continuation{tail: tail}, {:img, attrs, fun})
end
end
use Markright.Helpers.ImgLink
end