Current section
Files
Jump to
Current section
Files
src/jotkey.erl
-module(jotkey).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([default_renderer/0, render/3]).
-export_type([renderer/2]).
-type renderer(TAH, TAI) :: {renderer,
fun((gleam@dict:dict(binary(), binary()), gleam@option:option(binary()), binary(), TAI) -> TAH),
fun((list(TAH), TAI) -> TAH),
fun((gleam@dict:dict(binary(), binary()), integer(), list(TAH), TAI) -> TAH),
fun((jot:destination(), gleam@dict:dict(binary(), binary()), list(TAH), TAI) -> TAH),
fun((gleam@dict:dict(binary(), binary()), list(TAH), TAI) -> TAH),
fun((list(TAH), TAI) -> TAH),
fun((binary(), TAI) -> TAH),
fun((binary(), TAI) -> TAH),
fun((jot:destination(), binary(), TAI) -> TAH),
fun((TAI) -> TAH)}.
-file("/Users/raynerdls/ray.delossantos/apps/jot_to_lustre/src/jotkey.gleam", 52).
-spec default_renderer() -> renderer(lustre@internals@vdom:element(any()), any()).
default_renderer() ->
To_attributes = fun(Attrs) ->
gleam@dict:fold(
Attrs,
[],
fun(Attrs@1, Key, Val) ->
[lustre@attribute:attribute(Key, Val) | Attrs@1]
end
)
end,
{renderer,
fun(Attrs@2, Lang, Code, _) ->
Lang@1 = gleam@option:unwrap(Lang, <<"text"/utf8>>),
lustre@element@html:pre(
To_attributes(Attrs@2),
[lustre@element@html:code(
[lustre@attribute:attribute(
<<"data-lang"/utf8>>,
Lang@1
)],
[lustre@element:text(Code)]
)]
)
end,
fun(Content, _) -> lustre@element@html:em([], Content) end,
fun(Attrs@3, Level, Content@1, _) -> case Level of
1 ->
lustre@element@html:h1(To_attributes(Attrs@3), Content@1);
2 ->
lustre@element@html:h2(To_attributes(Attrs@3), Content@1);
3 ->
lustre@element@html:h3(To_attributes(Attrs@3), Content@1);
4 ->
lustre@element@html:h4(To_attributes(Attrs@3), Content@1);
5 ->
lustre@element@html:h5(To_attributes(Attrs@3), Content@1);
6 ->
lustre@element@html:h6(To_attributes(Attrs@3), Content@1);
_ ->
lustre@element@html:p(To_attributes(Attrs@3), Content@1)
end end,
fun(Destination, References, Content@2, _) -> case Destination of
{reference, Ref} ->
case gleam@dict:get(References, Ref) of
{ok, Url} ->
lustre@element@html:a(
[lustre@attribute:href(Url)],
Content@2
);
{error, _} ->
lustre@element@html:a(
[lustre@attribute:href(Ref)],
Content@2
)
end;
{url, Url@1} ->
lustre@element@html:a(
[lustre@attribute:attribute(<<"href"/utf8>>, Url@1)],
Content@2
)
end end,
fun(Attrs@4, Content@3, _) ->
lustre@element@html:p(To_attributes(Attrs@4), Content@3)
end,
fun(Content@4, _) -> lustre@element@html:strong([], Content@4) end,
fun(Text, _) -> lustre@element:text(Text) end,
fun(Content@5, _) ->
lustre@element@html:code([], [lustre@element:text(Content@5)])
end,
fun(Destination@1, Alt, _) -> case Destination@1 of
{reference, Ref@1} ->
lustre@element@html:img(
[lustre@attribute:src(Ref@1), lustre@attribute:alt(Alt)]
);
{url, Url@2} ->
lustre@element@html:img(
[lustre@attribute:src(Url@2), lustre@attribute:alt(Alt)]
)
end end,
fun(_) -> lustre@element@html:br([]) end}.
-file("/Users/raynerdls/ray.delossantos/apps/jot_to_lustre/src/jotkey.gleam", 196).
-spec text_content(list(jot:inline())) -> binary().
text_content(Segments) ->
gleam@list:fold(Segments, <<""/utf8>>, fun(Text, Inline) -> case Inline of
{text, Content} ->
<<Text/binary, Content/binary>>;
{link, Content@1, _} ->
<<Text/binary, (text_content(Content@1))/binary>>;
{emphasis, Content@2} ->
<<Text/binary, (text_content(Content@2))/binary>>;
{strong, Content@3} ->
<<Text/binary, (text_content(Content@3))/binary>>;
{code, Content@4} ->
<<Text/binary, Content@4/binary>>;
{image, _, _} ->
Text;
linebreak ->
Text
end end).
-file("/Users/raynerdls/ray.delossantos/apps/jot_to_lustre/src/jotkey.gleam", 146).
-spec render_inline(
jot:inline(),
gleam@dict:dict(binary(), binary()),
renderer(TBB, TBC),
TBC
) -> TBB.
render_inline(Inline, References, Renderer, Context) ->
case Inline of
{text, Text} ->
(erlang:element(8, Renderer))(Text, Context);
{link, Content, Destination} ->
(erlang:element(5, Renderer))(
Destination,
References,
gleam@list:map(
Content,
fun(_capture) ->
render_inline(_capture, References, Renderer, Context)
end
),
Context
);
{emphasis, Content@1} ->
(erlang:element(3, Renderer))(
gleam@list:map(
Content@1,
fun(_capture@1) ->
render_inline(_capture@1, References, Renderer, Context)
end
),
Context
);
{strong, Content@2} ->
(erlang:element(7, Renderer))(
gleam@list:map(
Content@2,
fun(_capture@2) ->
render_inline(_capture@2, References, Renderer, Context)
end
),
Context
);
{code, Content@3} ->
(erlang:element(9, Renderer))(Content@3, Context);
{image, Alt, Destination@1} ->
(erlang:element(10, Renderer))(
Destination@1,
text_content(Alt),
Context
);
linebreak ->
(erlang:element(11, Renderer))(Context)
end.
-file("/Users/raynerdls/ray.delossantos/apps/jot_to_lustre/src/jotkey.gleam", 116).
-spec render_block(
jot:container(),
gleam@dict:dict(binary(), binary()),
renderer(TAV, TAW),
TAW
) -> TAV.
render_block(Block, References, Renderer, Context) ->
case Block of
{paragraph, Attrs, Inline} ->
(erlang:element(6, Renderer))(
Attrs,
gleam@list:map(
Inline,
fun(_capture) ->
render_inline(_capture, References, Renderer, Context)
end
),
Context
);
{heading, Attrs@1, Level, Inline@1} ->
(erlang:element(4, Renderer))(
Attrs@1,
Level,
gleam@list:map(
Inline@1,
fun(_capture@1) ->
render_inline(_capture@1, References, Renderer, Context)
end
),
Context
);
{codeblock, Attrs@2, Language, Code} ->
(erlang:element(2, Renderer))(Attrs@2, Language, Code, Context)
end.
-file("/Users/raynerdls/ray.delossantos/apps/jot_to_lustre/src/jotkey.gleam", 107).
-spec render(jot:document(), renderer(TAO, TAP), TAP) -> list(TAO).
render(Document, Renderer, Context) ->
_pipe = erlang:element(2, Document),
gleam@list:map(
_pipe,
fun(_capture) ->
render_block(
_capture,
erlang:element(3, Document),
Renderer,
Context
)
end
).