-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; {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} -> <<<<<<<<<<<<">/binary, ">"/utf8>>/binary, (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, ">/binary, (gleam@int:to_string(Level))/binary>>/binary, ">\n"/utf8>>; horizontal_break -> <<"
\n"/utf8>>; {paragraph, Contents@3} when Tight -> _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>>); {paragraph, 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, "

\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, _} -> <<<<"
    \n"/utf8, (begin _pipe@10 = Items, _pipe@11 = gleam@list:map( _pipe@10, fun(_capture@4) -> list_item_to_html(_capture@4, Refs) end ), gleam@string:join(_pipe@11, <<""/utf8>>) end)/binary>>/binary, "
\n"/utf8>>; {ordered_list, Items@1, Start, _} -> <<<<<<<<"
    >/binary, "\">\n"/utf8>>/binary, (begin _pipe@12 = Items@1, _pipe@13 = gleam@list:map( _pipe@12, fun(_capture@5) -> list_item_to_html(_capture@5, Refs) end ), gleam@string:join(_pipe@13, <<""/utf8>>) end)/binary>>/binary, "
\n"/utf8>>; {unordered_list, Items@2, _} -> <<<<"\n"/utf8>> end. -spec list_item_to_html( commonmark@ast:list_item(), gleam@dict:dict(binary(), commonmark@ast:reference_()) ) -> binary(). list_item_to_html(Item, Refs) -> case Item of {list_item, []} -> <<"
  • \n"/utf8>>; {tight_list_item, []} -> <<"
  • \n"/utf8>>; {list_item, Contents} -> <<<<"
  • \n"/utf8, (begin _pipe = Contents, _pipe@1 = gleam@list:map( _pipe, fun(_capture) -> block_to_html(_capture, Refs, false) end ), gleam@string:join(_pipe@1, <<""/utf8>>) end)/binary>>/binary, "
  • \n"/utf8>>; {tight_list_item, Contents@1} -> R = begin _pipe@2 = Contents@1, lists:reverse(_pipe@2) end, Rest = begin _pipe@3 = R, _pipe@4 = gleam@list:drop(_pipe@3, 1), _pipe@5 = gleam@list:map(_pipe@4, fun(B) -> case B of {paragraph, C} -> block_to_html( {paragraph, gleam@list:concat( [C, [soft_line_break]] )}, Refs, true ); _ -> block_to_html(B, Refs, true) end end), _pipe@6 = lists:reverse(_pipe@5), gleam@string:join(_pipe@6, <<""/utf8>>) end, Last = case gleam@list:first(R) of {ok, Block} -> block_to_html(Block, Refs, true); {error, _} -> <<""/utf8>> end, <<<<<<"
  • "/utf8, Rest/binary>>/binary, Last/binary>>/binary, "
  • \n"/utf8>> end.