Current section
Files
Jump to
Current section
Files
src/testament@internal@markdown.erl
-module(testament@internal@markdown).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/testament/internal/markdown.gleam").
-export([parse_snippets/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-file("src/testament/internal/markdown.gleam", 7).
?DOC(false).
-spec parse_snippets(binary()) -> {list(binary()), list(binary())}.
parse_snippets(Content) ->
Rg@1 = case gleam@regexp:compile(
<<"^````?gleam(?:\\s*(\\w+))?([\\s\\S]*?)^````?$"/utf8>>,
{options, false, true}
) of
{ok, Rg} -> Rg;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => (<<"failed to compile markdown regex"/utf8>>),
file => <<?FILEPATH/utf8>>,
module => <<"testament/internal/markdown"/utf8>>,
function => <<"parse_snippets"/utf8>>,
line => 8,
value => _assert_fail,
start => 167,
'end' => 302,
pattern_start => 178,
pattern_end => 184})
end,
_pipe = Rg@1,
_pipe@1 = gleam@regexp:scan(_pipe, Content),
_pipe@13 = gleam@list:map(
_pipe@1,
fun(Match) -> _pipe@2 = erlang:element(2, Match),
_pipe@3 = gleam@string:replace(
_pipe@2,
<<"````gleam"/utf8>>,
<<""/utf8>>
),
_pipe@4 = gleam@string:replace(
_pipe@3,
<<"```gleam"/utf8>>,
<<""/utf8>>
),
_pipe@5 = gleam@string:replace(
_pipe@4,
<<"````"/utf8>>,
<<""/utf8>>
),
_pipe@6 = gleam@string:replace(_pipe@5, <<"```"/utf8>>, <<""/utf8>>),
_pipe@7 = gleam@string:trim(_pipe@6),
_pipe@8 = glexer:new(_pipe@7),
_pipe@9 = glexer:discard_comments(_pipe@8),
_pipe@10 = glexer:lex(_pipe@9),
_pipe@11 = glexer:to_source(_pipe@10),
_pipe@12 = gleam@string:split(_pipe@11, <<"\n"/utf8>>),
gleam@list:fold(
_pipe@12,
{[], <<""/utf8>>},
fun(Acc, Line) ->
case gleam_stdlib:string_starts_with(
Line,
<<"import"/utf8>>
) of
true ->
gleam@pair:map_first(
Acc,
fun(_capture) ->
gleam@list:prepend(_capture, Line)
end
);
_ ->
gleam@pair:map_second(
Acc,
fun(L) ->
erlang:list_to_binary(
[L, <<"\n"/utf8>>, Line]
)
end
)
end
end
) end
),
_pipe@16 = gleam@list:fold(
_pipe@13,
{[], []},
fun(Acc@1, Block) -> _pipe@14 = Acc@1,
_pipe@15 = gleam@pair:map_first(
_pipe@14,
fun(_capture@1) ->
lists:append(_capture@1, gleam@pair:first(Block))
end
),
gleam@pair:map_second(
_pipe@15,
fun(_capture@2) ->
lists:append(_capture@2, [gleam@pair:second(Block)])
end
) end
),
gleam@pair:map_first(_pipe@16, fun gleam@list:unique/1).