-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/1, block_to_html/1]).
-spec sanitize_href_property(binary()) -> binary().
sanitize_href_property(Prop) ->
_pipe = Prop,
_pipe@1 = gleam@string:replace(_pipe, <<"&"/utf8>>, <<"&"/utf8>>),
gleam@string:replace(_pipe@1, <<"\""/utf8>>, <<"%22"/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>>),
gleam@string:replace(_pipe@2, <<">"/utf8>>, <<">"/utf8>>).
-spec inline_to_html(commonmark@ast:inline_node()) -> binary().
inline_to_html(Inline) ->
case Inline of
{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 inline_to_html/1),
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 inline_to_html/1),
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 inline_to_html/1),
gleam@string:join(_pipe@7, <<""/utf8>>)
end)/binary>>/binary,
""/utf8>>;
{html_inline, Html} ->
Html;
{image, _, _} ->
<<"Image"/utf8>>;
{reference_link, _, _} ->
<<"Link"/utf8>>;
{link, _, _, _} ->
<<"Link"/utf8>>;
{named_entity, <<"amp"/utf8>>, _} ->
<<"&"/utf8>>;
{named_entity, _, Cp} ->
gleam_stdlib:utf_codepoint_list_to_string(Cp);
{numeric_character_reference, Cp@1, _} ->
gleam_stdlib:utf_codepoint_list_to_string([Cp@1])
end.
-spec block_to_html(commonmark@ast:block_node()) -> binary().
block_to_html(Block) ->
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@4 = Contents@3, _pipe@5 = gleam@list:map(_pipe@4, fun inline_to_html/1), gleam@string:join(_pipe@5, <<""/utf8>>) end)/binary>>/binary, "
\n"/utf8>>; {html_block, Html} -> <>; {block_quote, Contents@4} -> <<<<""/utf8, (begin _pipe@6 = Contents@4, _pipe@7 = gleam@list:map(_pipe@6, fun block_to_html/1), gleam@string:join(_pipe@7, <<""/utf8>>) end)/binary>>/binary, "\n"/utf8>>; {ordered_list, Items, 1, _} -> <<<<"