-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defs.lib.papyri
57 lines (49 loc) · 1.39 KB
/
defs.lib.papyri
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@let(nav_root_links=[
[`./`, `Home`],
[`./tutorial.html`, `Tutorial`],
])...
@fn fa_anchor($_icon: str, $href?: str) $v: inline -> {
<a class="anchor" href?=$href>
<i class="anchor-icon fas $_icon"/>
$v
</a>
}
@export @fn h1 $t: inline -> {
<h1>@fa_anchor(`fa-link`, href="") $t</h1>
}
@export @fn h2 $t: inline -> {
@let(id=@str::unique_id $t)
<h2 id=$id>@fa_anchor(`fa-hashtag`, href="\#$id") $t</h2>
}
@fn get_headings $content: html -> @match $content {
{<h2 **_><a href=$link **_>{_ *$title}</a></h2> *$tail} -> [@href($link) $title, *@get_headings $tail],
{_ *$tail} -> @get_headings $tail,
{} -> [],
}
@fn get_nav($_link_title: str) $content: html ->
@nav_root_links::map(@fn $link -> @match $link {
[$url, $title] -> {
@href($url) $title
@match $title {
=$_link_title -> @get_headings $content,
_ -> .,
}
},
}).
@let(old_page=$page)...
@export @fn page($_link_title: str) $content -> {
@old_page(
title={Papyri: a programmable markup language},
web_root=`./`,
header=<nav data_title="Navigation">@get_nav($_link_title) $content</nav>,
) {
$content
}
}
@export @fn shell $v: str -> {
@code_block(language=.) $v
}
@export @fn info $v: html -> {
@fa_anchor(`fa-info-circle`).
<div class="info panel">$v</div>
}