Current section
Files
Jump to
Current section
Files
src/glemini@gemtext.erl
-module(glemini@gemtext).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([line_to_string/1, lines_to_string/1, text/1, link/1, link_with_caption/2, heading1/1, heading2/1, heading3/1, list_item/1, qoute/1, preformatted/1, preformatted_with_caption/2, blank_line/0]).
-export_type([line/0]).
-opaque line() :: {text, binary()} |
{link, binary(), gleam@option:option(binary())} |
{heading1, binary()} |
{heading2, binary()} |
{heading3, binary()} |
{list_item, binary()} |
{qoute, binary()} |
{preformatted, binary(), gleam@option:option(binary())}.
-spec line_to_string(line()) -> binary().
line_to_string(Line) ->
case Line of
{text, Text} ->
Text;
{link, Uri, {some, Caption}} ->
<<<<<<"=> "/utf8, Uri/binary>>/binary, " "/utf8>>/binary,
Caption/binary>>;
{link, Uri@1, none} ->
<<"=> "/utf8, Uri@1/binary>>;
{heading1, Text@1} ->
<<"# "/utf8, Text@1/binary>>;
{heading2, Text@2} ->
<<"## "/utf8, Text@2/binary>>;
{heading3, Text@3} ->
<<"### "/utf8, Text@3/binary>>;
{list_item, Text@4} ->
<<"* "/utf8, Text@4/binary>>;
{qoute, Text@5} ->
<<"> "/utf8, Text@5/binary>>;
{preformatted, Text@6, {some, Caption@1}} ->
<<<<<<<<"```"/utf8, Caption@1/binary>>/binary, "\n"/utf8>>/binary,
Text@6/binary>>/binary,
"\n```"/utf8>>;
{preformatted, Text@7, none} ->
<<<<"```\n"/utf8, Text@7/binary>>/binary, "\n```"/utf8>>
end.
-spec lines_to_string(list(line())) -> binary().
lines_to_string(Lines) ->
_pipe = gleam@list:map(Lines, fun line_to_string/1),
gleam@string:join(_pipe, <<"\n"/utf8>>).
-spec text(binary()) -> line().
text(Text) ->
{text, Text}.
-spec link(binary()) -> line().
link(Uri) ->
{link, Uri, none}.
-spec link_with_caption(binary(), binary()) -> line().
link_with_caption(Uri, Text) ->
{link, Uri, {some, Text}}.
-spec heading1(binary()) -> line().
heading1(Text) ->
{heading1, Text}.
-spec heading2(binary()) -> line().
heading2(Text) ->
{heading2, Text}.
-spec heading3(binary()) -> line().
heading3(Text) ->
{heading3, Text}.
-spec list_item(binary()) -> line().
list_item(Text) ->
{list_item, Text}.
-spec qoute(binary()) -> line().
qoute(Text) ->
{qoute, Text}.
-spec preformatted(binary()) -> line().
preformatted(Text) ->
{preformatted, Text, none}.
-spec preformatted_with_caption(binary(), binary()) -> line().
preformatted_with_caption(Text, Caption) ->
{preformatted, Text, {some, Caption}}.
-spec blank_line() -> line().
blank_line() ->
{text, <<""/utf8>>}.