Current section
Files
Jump to
Current section
Files
src/commonmark@internal@parser@inline.erl
-module(commonmark@internal@parser@inline).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([parse_text/1]).
-export_type([inline_state/0]).
-type inline_state() :: {text_accumulator, list(binary())} |
{autolink_accumulator, list(binary())}.
-spec do_parse_text(
list(binary()),
inline_state(),
list(commonmark@ast:inline_node())
) -> list(commonmark@ast:inline_node()).
do_parse_text(Text, State, Acc) ->
case {State, Text} of
{{autolink_accumulator, Ts}, []} ->
[{plain_text,
begin
_pipe = [<<"<"/utf8>> | lists:reverse(Ts)],
gleam@string:join(_pipe, <<""/utf8>>)
end} |
Acc];
{{text_accumulator, Ts@1}, []} ->
_pipe@4 = [{plain_text,
begin
_pipe@1 = Ts@1,
_pipe@2 = lists:reverse(_pipe@1),
_pipe@3 = gleam@string:join(_pipe@2, <<""/utf8>>),
gleam@string:trim(_pipe@3)
end} |
Acc],
lists:reverse(_pipe@4);
{{text_accumulator, Ts@2},
[<<" "/utf8>>, <<" "/utf8>>, <<"\n"/utf8>> | Gs]} ->
do_parse_text(
Gs,
{text_accumulator, []},
[hard_line_break,
{plain_text,
begin
_pipe@5 = Ts@2,
_pipe@6 = lists:reverse(_pipe@5),
_pipe@7 = gleam@string:join(_pipe@6, <<""/utf8>>),
gleam@string:trim(_pipe@7)
end} |
Acc]
);
{{text_accumulator, Ts@2}, [<<"\\"/utf8>>, <<"\n"/utf8>> | Gs]} ->
do_parse_text(
Gs,
{text_accumulator, []},
[hard_line_break,
{plain_text,
begin
_pipe@5 = Ts@2,
_pipe@6 = lists:reverse(_pipe@5),
_pipe@7 = gleam@string:join(_pipe@6, <<""/utf8>>),
gleam@string:trim(_pipe@7)
end} |
Acc]
);
{{autolink_accumulator, Ts@3},
[<<" "/utf8>>, <<" "/utf8>>, <<"\n"/utf8>> | Gs@1]} ->
do_parse_text(
Gs@1,
{text_accumulator, []},
[hard_line_break,
{plain_text,
begin
_pipe@8 = lists:reverse([<<"<"/utf8>> | Ts@3]),
gleam@string:join(_pipe@8, <<""/utf8>>)
end} |
Acc]
);
{{autolink_accumulator, Ts@3}, [<<"\\"/utf8>>, <<"\n"/utf8>> | Gs@1]} ->
do_parse_text(
Gs@1,
{text_accumulator, []},
[hard_line_break,
{plain_text,
begin
_pipe@8 = lists:reverse([<<"<"/utf8>> | Ts@3]),
gleam@string:join(_pipe@8, <<""/utf8>>)
end} |
Acc]
);
{{text_accumulator, Ts@4}, [<<"\n"/utf8>> | Gs@2]} ->
do_parse_text(
Gs@2,
{text_accumulator, []},
[soft_line_break,
{plain_text,
begin
_pipe@9 = Ts@4,
_pipe@10 = lists:reverse(_pipe@9),
_pipe@11 = gleam@string:join(_pipe@10, <<""/utf8>>),
gleam@string:trim(_pipe@11)
end} |
Acc]
);
{{autolink_accumulator, Ts@5}, [<<"\n"/utf8>> | Gs@3]} ->
do_parse_text(
Gs@3,
{text_accumulator, []},
[soft_line_break,
{plain_text,
begin
_pipe@12 = lists:reverse([<<"<"/utf8>> | Ts@5]),
gleam@string:join(_pipe@12, <<""/utf8>>)
end} |
Acc]
);
{{text_accumulator, Ts@6}, [<<"<"/utf8>> | Gs@4]} ->
do_parse_text(
Gs@4,
{autolink_accumulator, []},
[{plain_text,
begin
_pipe@13 = Ts@6,
_pipe@14 = lists:reverse(_pipe@13),
gleam@string:join(_pipe@14, <<""/utf8>>)
end} |
Acc]
);
{{autolink_accumulator, Ts@7}, [<<"\t"/utf8>> = Space | Gs@5]} ->
do_parse_text(
Gs@5,
{text_accumulator, [Space | lists:append(Ts@7, [<<"<"/utf8>>])]},
Acc
);
{{autolink_accumulator, Ts@7}, [<<" "/utf8>> = Space | Gs@5]} ->
do_parse_text(
Gs@5,
{text_accumulator, [Space | lists:append(Ts@7, [<<"<"/utf8>>])]},
Acc
);
{{autolink_accumulator, Ts@8}, [<<">"/utf8>> | Gs@6]} ->
do_parse_text(
Gs@6,
{text_accumulator, []},
[commonmark@internal@parser@helpers:parse_autolink(
begin
_pipe@15 = Ts@8,
_pipe@16 = lists:reverse(_pipe@15),
gleam@string:join(_pipe@16, <<""/utf8>>)
end
) |
Acc]
);
{{autolink_accumulator, Ts@9}, [G | Gs@7]} ->
do_parse_text(Gs@7, {autolink_accumulator, [G | Ts@9]}, Acc);
{{text_accumulator, Ts@10}, [G@1 | Gs@8]} ->
do_parse_text(Gs@8, {text_accumulator, [G@1 | Ts@10]}, Acc)
end.
-spec parse_text(binary()) -> list(commonmark@ast:inline_node()).
parse_text(Text) ->
_pipe = Text,
_pipe@1 = gleam@string:to_graphemes(_pipe),
do_parse_text(_pipe@1, {text_accumulator, []}, []).