Packages
earmark
1.4.48
1.5.0-pre1
retired
1.5.0-pre
retired
1.4.49
retired
1.4.48
retired
1.4.47
retired
1.4.46
retired
1.4.45
retired
1.4.44
retired
1.4.43
retired
1.4.42
retired
1.4.41
retired
1.4.40
retired
1.4.39
retired
1.4.38
retired
1.4.37
retired
1.4.36
retired
1.4.35
retired
1.4.34
retired
1.4.33
retired
1.4.32
retired
1.4.31
retired
1.4.30
retired
1.4.29
retired
1.4.28
retired
1.4.27
retired
1.4.26
retired
1.4.25
retired
1.4.24
retired
1.4.23
retired
1.4.22
retired
1.4.21
retired
1.4.20
retired
1.4.19
retired
1.4.18
retired
1.4.17
retired
1.4.16
retired
1.4.16-pre2
retired
1.4.16-pre1
retired
1.4.16-pre
retired
1.4.15
retired
1.4.14
retired
1.4.13
retired
1.4.12
retired
1.4.10
retired
1.4.9
retired
1.4.8
retired
1.4.7
retired
1.4.6
retired
1.4.5
retired
1.4.4
retired
1.4.3
retired
1.4.2
retired
1.4.1
retired
1.4.0
retired
1.3.6
retired
1.3.5
retired
1.3.4
retired
1.3.3
retired
1.3.2
retired
1.3.1
retired
1.3.0
retired
1.2.6
retired
1.2.5
retired
1.2.4
retired
1.2.3
retired
1.2.2
retired
1.2.1
retired
1.2.0
retired
1.1.1
retired
1.1.0
retired
1.0.3
retired
1.0.2
retired
1.0.1
retired
1.0.0
retired
0.2.1
retired
0.2.0
retired
0.1.19
retired
0.1.18
retired
0.1.17
retired
0.1.16
retired
0.1.15
retired
0.1.14
retired
0.1.13
retired
0.1.12
retired
0.1.10
retired
0.1.9
retired
0.1.8
retired
0.1.7
retired
0.1.6
retired
0.1.5
retired
0.1.4
retired
0.1.3
retired
0.1.2
retired
0.1.1
retired
0.1.0
retired
Earmark is a pure-Elixir Markdown converter. It is intended to be used as a library (just call Earmark.as_html), but can also be used as a command-line tool (run mix escript.build first). Output generation is pluggable.
Retired package: Deprecated - Earmark is no longer maintained. Migrate to a replacement, for example MDEx (https://hex.pm/packages/mdex).
Security advisory:
This version has known vulnerabilities.
View advisories
Current section
Files
Jump to
Current section
Files
lib/earmark_parser/parser/footnote_parser.ex
defmodule Earmark.Parser.Parser.FootnoteParser do
alias Earmark.Parser.{Block, Enum.Ext, Line}
@moduledoc false
def parse_fn_defs([fn_def | rest], result, options) do
acc =
{[fn_def.content], [%Block.FnList{blocks: [_block_fn_def(fn_def)]} | result], %{}, options}
rest
|> Ext.reduce_with_end(acc, &_parse_fn_def_reduce/2)
end
defp _parse_fn_def_reduce(ele_or_end, acc)
defp _parse_fn_def_reduce({:element, %Line.FnDef{content: content}=fn_def}, acc) do
{result1, footnotes, options1} = _complete_fn_def_block(acc, fn_def)
{[content], result1, footnotes, options1}
end
defp _parse_fn_def_reduce({:element, %{line: line}}, acc) do
_prepend_to_first_in4(line, acc)
end
defp _parse_fn_def_reduce(:end, acc) do
{[fn_list | rest], footnotes, options} = _complete_fn_def_block(acc)
{[%{fn_list | blocks: Enum.reverse(fn_list.blocks)} | rest], footnotes, options}
end
defp _prepend_to_first_in4(element, {a, b, c, d}) do
{[element | a], b, c, d}
end
defp _block_fn_def(%Line.FnDef{} = fn_def) do
%Block.FnDef{id: fn_def.id, lnb: fn_def.lnb}
end
defp _complete_fn_def_block(
{input, [%Block.FnList{blocks: [open_fn | closed_fns]} | rest], footnotes, options},
new_fn_def \\ nil
) do
# `_footnotes1` should be empty but let us not change the shape of parse depending
# on options or the value of recursive?
{inner_blocks, _links, _footnotes1, options1} = Earmark.Parser.Parser.parse(Enum.reverse(input), options, true)
closed_fn = %{open_fn | blocks: inner_blocks}
footnotes1 = Map.put(footnotes, closed_fn.id, closed_fn)
fn_blocks =
if new_fn_def do
[_block_fn_def(new_fn_def), closed_fn | closed_fns]
else
[closed_fn | closed_fns]
end
{[%Block.FnList{blocks: fn_blocks} | rest], footnotes1, options1}
end
end
# SPDX-License-Identifier: Apache-2.0