Current section
Files
Jump to
Current section
Files
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 => 15})
end,
_pipe = Document,
_pipe@1 = gleam@string:replace(
_pipe,
<<"\x{0000}"/utf8>>,
<<"\x{FFFD}"/utf8>>
),
_pipe@2 = gleam@regex:split(Line_splitter, _pipe@1),
commonmark@internal@parser@block:parse_document(_pipe@2).
-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@html:block_to_html(
_capture,
erlang:element(3, Document),
false
)
end
),
gleam@string:join(_pipe@1, <<""/utf8>>).
-spec to_html_strict(commonmark@ast:document()) -> {ok, binary()} | {error, nil}.
to_html_strict(Document) ->
_pipe = erlang:element(2, Document),
_pipe@1 = gleam@list:map(
_pipe,
fun(_capture) ->
commonmark@internal@html:block_to_html(
_capture,
erlang:element(3, Document),
false
)
end
),
_pipe@2 = gleam@string:join(_pipe@1, <<""/utf8>>),
{ok, _pipe@2}.
-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, nil}.
render_to_html_strict(Document) ->
_pipe = Document,
_pipe@1 = parse(_pipe),
to_html_strict(_pipe@1).