Packages
earmark_parser
1.4.26
1.4.46
1.4.45
1.4.44
1.4.43
1.4.42
1.4.41
1.4.40
1.4.39
1.4.38
1.4.37
1.4.36
1.4.35
1.4.34
1.4.33
1.4.32
1.4.31
1.4.30
1.4.29
1.4.28
1.4.27
1.4.26
1.4.25
1.4.24
1.4.23
1.4.22
1.4.21
1.4.20
1.4.20-pre
1.4.19
1.4.18
1.4.17
1.4.16
1.4.16-pre2
1.4.16-pre1
1.4.16-pre
1.4.15
1.4.13
1.4.12
1.4.11
1.4.10
1.4.9
1.4.8
AST parser and generator for Markdown
Current section
Files
Jump to
Current section
Files
lib/earmark_parser/ast/renderer/footnote_renderer.ex
defmodule EarmarkParser.Ast.Renderer.FootnoteRenderer do
import EarmarkParser.Ast.Emitter
alias EarmarkParser.{AstRenderer, Block, Context, Message}
import Context, only: [clear_value: 1, prepend: 2]
@moduledoc false
@empty_set MapSet.new([])
def render_defined_fns(%Block.FnList{blocks: footnotes}, context) do
{elements, errors} = render_footnote_blocks(footnotes, context)
ast =
emit(
"div",
[
emit("hr"),
emit("ol", elements)
],
class: "footnotes"
)
prepend(context, ast) |> Message.add_messages(errors)
end
defp _render_footnote_def(%Block.FnDef{blocks: blocks, id: id}, {ast, errors, context}=acc) do
if MapSet.member?(context.referenced_footnote_ids, id) do
context1 = AstRenderer.render(blocks, clear_value(context))
a_attrs = %{title: "return to article", class: "reversefootnote", href: "#fnref:#{id}"}
footnote_li_ast =
emit("li", [emit("a", ["↩"], a_attrs) | context1.value],
id: "fn:#{id}")
{[footnote_li_ast|ast], MapSet.union(errors, context1.options.messages), context}
else
acc
end
end
defp render_footnote_blocks(footnotes, context) do
{elements, errors, _} =
footnotes
|> Enum.reduce({[], @empty_set, context}, &_render_footnote_def/2)
{elements|>Enum.reverse, errors}
end
end
# SPDX-License-Identifier: Apache-2.0