-module(commonmark@internal@html).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([sanitize_href_property/1, sanitize_plain_text/1, inline_to_html/2, block_to_html/3]).
-spec sanitize_href_property(binary()) -> binary().
sanitize_href_property(Prop) ->
_pipe = Prop,
_pipe@1 = gleam@string:replace(_pipe, <<"&"/utf8>>, <<"&"/utf8>>),
_pipe@2 = gleam@string:replace(_pipe@1, <<"\""/utf8>>, <<"%22"/utf8>>),
gleam@string:replace(_pipe@2, <<"\\"/utf8>>, <<"%5C"/utf8>>).
-spec sanitize_plain_text(binary()) -> binary().
sanitize_plain_text(Text) ->
_pipe = Text,
_pipe@1 = gleam@string:replace(_pipe, <<"&"/utf8>>, <<"&"/utf8>>),
_pipe@2 = gleam@string:replace(_pipe@1, <<"\""/utf8>>, <<"""/utf8>>),
_pipe@3 = gleam@string:replace(_pipe@2, <<"<"/utf8>>, <<"<"/utf8>>),
gleam@string:replace(_pipe@3, <<">"/utf8>>, <<">"/utf8>>).
-spec inline_to_html(
commonmark@ast:inline_node(),
gleam@dict:dict(binary(), commonmark@ast:reference_())
) -> binary().
inline_to_html(Inline, Refs) ->
case Inline of
{plain_text, Contents} ->
_pipe = Contents,
sanitize_plain_text(_pipe);
hard_line_break ->
<<"
\n"/utf8>>;
soft_line_break ->
<<"\n"/utf8>>;
{uri_autolink, Href} ->
<<<<<<<<">/binary,
"\">"/utf8>>/binary,
Href/binary>>/binary,
""/utf8>>;
{email_autolink, Email} ->
<<<<<<<<">/binary,
"\">"/utf8>>/binary,
Email/binary>>/binary,
""/utf8>>;
{code_span, Contents@1} ->
<<<<""/utf8,
(begin
_pipe@1 = Contents@1,
sanitize_plain_text(_pipe@1)
end)/binary>>/binary,
""/utf8>>;
{emphasis, Contents@2, _} ->
<<<<""/utf8,
(begin
_pipe@2 = Contents@2,
_pipe@3 = gleam@list:map(
_pipe@2,
fun(_capture) -> inline_to_html(_capture, Refs) end
),
gleam@string:join(_pipe@3, <<""/utf8>>)
end)/binary>>/binary,
""/utf8>>;
{strong_emphasis, Contents@3, _} ->
<<<<""/utf8,
(begin
_pipe@4 = Contents@3,
_pipe@5 = gleam@list:map(
_pipe@4,
fun(_capture@1) ->
inline_to_html(_capture@1, Refs)
end
),
gleam@string:join(_pipe@5, <<""/utf8>>)
end)/binary>>/binary,
""/utf8>>;
{strike_through, Contents@4} ->
<<<<""/utf8,
(begin
_pipe@6 = Contents@4,
_pipe@7 = gleam@list:map(
_pipe@6,
fun(_capture@2) ->
inline_to_html(_capture@2, Refs)
end
),
gleam@string:join(_pipe@7, <<""/utf8>>)
end)/binary>>/binary,
""/utf8>>;
{html_inline, Html} ->
Html;
{reference_image, _, _} ->
<<"Image"/utf8>>;
{image, _, _, _} ->
<<"Image"/utf8>>;
{reference_link, _, _} ->
<<"Link"/utf8>>;
{link, _, _, _} ->
<<"Link"/utf8>>
end.
-spec block_to_html(
commonmark@ast:block_node(),
gleam@dict:dict(binary(), commonmark@ast:reference_()),
boolean()
) -> binary().
block_to_html(Block, Refs, Tight) ->
case Block of
{code_block, none, _, Contents} ->
<<<<"
"/utf8,
(begin
_pipe = Contents,
sanitize_plain_text(_pipe)
end)/binary>>/binary,
"\n"/utf8>>;
{code_block, {some, Info}, _, Contents@1} ->
<<<<<<<<">/binary,
"\">"/utf8>>/binary,
(begin
_pipe@1 = Contents@1,
sanitize_plain_text(_pipe@1)
end)/binary>>/binary,
"\n"/utf8>>;
{heading, Level, Contents@2} ->
<<<<<<<<<<<<""/utf8, (begin _pipe@6 = Contents@4, _pipe@7 = gleam@list:map( _pipe@6, fun(_capture@2) -> inline_to_html(_capture@2, Refs) end ), gleam@string:join(_pipe@7, <<""/utf8>>) end)/binary>>/binary, "
\n"/utf8>>; {html_block, Html} -> <>; {block_quote, Contents@5} -> <<<<"\n"/utf8, (begin _pipe@8 = Contents@5, _pipe@9 = gleam@list:map( _pipe@8, fun(_capture@3) -> block_to_html(_capture@3, Refs, false) end ), gleam@string:join(_pipe@9, <<""/utf8>>) end)/binary>>/binary, "\n"/utf8>>; {ordered_list, Items, 1, _} -> <<<<"