Current section

Files

Jump to
commonmark src commonmark.erl
Raw

src/commonmark.erl

-module(commonmark).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([parse/1, to_html/1, to_html_strict/1, render_to_html/1, render_to_html_strict/1]).
-spec parse(binary()) -> commonmark@ast:document().
parse(Document) ->
_assert_subject = gleam@regex:from_string(<<"\r?\n|\r\n?"/utf8>>),
{ok, Line_splitter} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail,
module => <<"commonmark"/utf8>>,
function => <<"parse"/utf8>>,
line => 17})
end,
_assert_subject@1 = begin
_pipe = 16#fffd,
_pipe@1 = gleam@string:utf_codepoint(_pipe),
gleam@result:map(
_pipe@1,
fun(X) -> gleam_stdlib:utf_codepoint_list_to_string([X]) end
)
end,
{ok, Replacement_string} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Assertion pattern match failed"/utf8>>,
value => _assert_fail@1,
module => <<"commonmark"/utf8>>,
function => <<"parse"/utf8>>,
line => 18})
end,
_pipe@2 = Document,
_pipe@6 = gleam@list:fold(
[0],
_pipe@2,
fun(D, Cp) -> _pipe@3 = gleam@string:utf_codepoint(Cp),
_pipe@4 = gleam@result:map(
_pipe@3,
fun(X@1) -> gleam_stdlib:utf_codepoint_list_to_string([X@1]) end
),
_pipe@5 = gleam@result:map(
_pipe@4,
fun(_capture) ->
gleam@string:replace(D, _capture, Replacement_string)
end
),
gleam@result:unwrap(_pipe@5, D) end
),
_pipe@7 = gleam@regex:split(Line_splitter, _pipe@6),
commonmark@internal@parser@block:parse_document(_pipe@7).
-spec to_html(commonmark@ast:document()) -> binary().
to_html(Document) ->
_pipe = erlang:element(2, Document),
_pipe@1 = gleam@list:map(
_pipe,
fun(_capture) ->
commonmark@internal@renderer@html:block_to_html_safe(
_capture,
erlang:element(3, Document),
false
)
end
),
gleam@string:join(_pipe@1, <<""/utf8>>).
-spec to_html_strict(commonmark@ast:document()) -> {ok, binary()} |
{error, commonmark@ast:render_error()}.
to_html_strict(Document) ->
_pipe = erlang:element(2, Document),
_pipe@1 = gleam@list:map(
_pipe,
fun(_capture) ->
commonmark@internal@renderer@html:block_to_html(
_capture,
erlang:element(3, Document),
false
)
end
),
_pipe@2 = gleam@result:all(_pipe@1),
gleam@result:map(
_pipe@2,
fun(_capture@1) -> gleam@string:join(_capture@1, <<""/utf8>>) end
).
-spec render_to_html(binary()) -> binary().
render_to_html(Document) ->
_pipe = Document,
_pipe@1 = parse(_pipe),
to_html(_pipe@1).
-spec render_to_html_strict(binary()) -> {ok, binary()} |
{error, commonmark@ast:render_error()}.
render_to_html_strict(Document) ->
_pipe = Document,
_pipe@1 = parse(_pipe),
to_html_strict(_pipe@1).