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

lib/markright/finalizers/blockquote.ex

defmodule Markright.Finalizers.Blockquote do
@moduledoc ~S"""
Finalizer for `blockquote` tag: makes last AST element fancy if it’s a link.
"""
@behaviour Markright.Finalizer
@spec finalize(Markright.Continuation.t) :: Markright.Continuation.t
def finalize(%Markright.Continuation{ast: {:blockquote, bq_attrs, bq_ast}} = cont) when is_list(bq_ast) do
case :lists.reverse(bq_ast) do
[{:a, %{href: href} = attrs, text} | t] ->
img = with [capture] <- Regex.run(~r|\Ahttps?://[^/]+|, href),
do: {:img, %{alt: "favicon", src: capture <> "/favicon.png", style: "height:16px;margin-bottom:-2px;"}, nil}
patched = :lists.reverse([{:br, %{}, nil}, "— ", img, " ", {:a, attrs, text}])
%Markright.Continuation{cont | ast: {:blockquote, Map.put(bq_attrs, :cite, href), :lists.reverse(patched ++ t)}}
_ -> cont
end
end
def finalize(%Markright.Continuation{} = cont), do: cont
##############################################################################
end