2024-07-08 12:25:56 +00:00
|
|
|
|
|
|
|
// .--------------------------------------------------------------------------.
|
|
|
|
// | Glossary Utilities |
|
|
|
|
// '--------------------------------------------------------------------------'
|
|
|
|
|
|
|
|
// Author: Sven Vogel
|
|
|
|
// Edited: 08.07.2024
|
|
|
|
// License: MIT
|
|
|
|
|
|
|
|
#let glossary(entries) = {
|
|
|
|
|
2024-08-12 16:09:14 +00:00
|
|
|
assert(
|
|
|
|
type(entries) == dictionary,
|
|
|
|
message: "The glossary is not a dictionary",
|
|
|
|
)
|
|
|
|
|
2024-08-14 09:57:27 +00:00
|
|
|
let processed_glossary = (:)
|
|
|
|
|
2024-08-12 16:09:14 +00:00
|
|
|
for (k, v) in entries.pairs() {
|
2024-07-08 12:25:56 +00:00
|
|
|
assert(
|
2024-08-12 16:09:14 +00:00
|
|
|
type(v) == dictionary,
|
|
|
|
message: "The glossary entry `" + k + "` is not a dictionary",
|
2024-07-08 12:25:56 +00:00
|
|
|
)
|
|
|
|
|
2024-08-12 16:09:14 +00:00
|
|
|
for key in v.keys() {
|
2024-07-08 12:25:56 +00:00
|
|
|
assert(
|
2024-08-12 16:09:14 +00:00
|
|
|
key in ("short", "long", "desc", "group"),
|
|
|
|
message: "Found unexpected key `" + key + "` in glossary entry `" + k,
|
|
|
|
)
|
|
|
|
}
|
2024-07-08 12:25:56 +00:00
|
|
|
|
2024-08-12 16:09:14 +00:00
|
|
|
assert(
|
|
|
|
type(v.short) == str,
|
|
|
|
message: "The short form of glossary entry `" + k + "` is not a string",
|
|
|
|
)
|
2024-07-08 12:25:56 +00:00
|
|
|
|
2024-08-12 16:09:14 +00:00
|
|
|
if "long" in v {
|
2024-07-08 12:25:56 +00:00
|
|
|
assert(
|
2024-08-12 16:09:14 +00:00
|
|
|
type(v.long) == str,
|
|
|
|
message: "The long form of glossary entry `" + k + "` is not a string",
|
|
|
|
)
|
|
|
|
}
|
2024-07-08 12:25:56 +00:00
|
|
|
|
2024-08-12 16:09:14 +00:00
|
|
|
if "desc" in v {
|
|
|
|
assert(
|
|
|
|
type(v.desc) == str,
|
|
|
|
message: "The description of glossary entry `" + k + "` is not a string",
|
|
|
|
)
|
|
|
|
}
|
2024-07-08 12:25:56 +00:00
|
|
|
|
2024-08-12 16:09:14 +00:00
|
|
|
if "group" in v {
|
|
|
|
assert(
|
|
|
|
type(v.group) == str,
|
|
|
|
message: "The optional group of glossary entry `" + k + "` is not a string",
|
|
|
|
)
|
|
|
|
} else {
|
2024-08-14 09:57:27 +00:00
|
|
|
let acronym_group = if (context text.lang) == "de" {
|
|
|
|
"Akronyme"
|
|
|
|
} else {
|
|
|
|
"Acronyms"
|
|
|
|
}
|
|
|
|
|
|
|
|
let glossary_group = if (context text.lang) == "de" {
|
|
|
|
"Begriffe"
|
|
|
|
} else {
|
|
|
|
"Glossary"
|
|
|
|
}
|
|
|
|
|
2024-08-12 16:09:14 +00:00
|
|
|
let group = if "long" in v {
|
2024-08-14 09:57:27 +00:00
|
|
|
acronym_group
|
2024-07-08 12:25:56 +00:00
|
|
|
} else {
|
2024-08-14 09:57:27 +00:00
|
|
|
glossary_group
|
2024-07-08 12:25:56 +00:00
|
|
|
}
|
2024-08-12 16:09:14 +00:00
|
|
|
|
2024-08-14 09:57:27 +00:00
|
|
|
// create dedicated entries for
|
|
|
|
// acronym and glossary
|
|
|
|
if "long" in v and "desc" in v {
|
|
|
|
processed_glossary.insert(k, (short: v.short, long: v.long, group: acronym_group))
|
2024-08-22 08:43:13 +00:00
|
|
|
processed_glossary.insert(k + "__glossary_entry", (short: v.short, desc: v.desc, long: v.long, group: glossary_group))
|
2024-08-14 09:57:27 +00:00
|
|
|
} else {
|
|
|
|
processed_glossary.insert(k, v)
|
|
|
|
processed_glossary.at(k).group = group
|
|
|
|
}
|
2024-07-08 12:25:56 +00:00
|
|
|
}
|
2024-08-12 16:09:14 +00:00
|
|
|
}
|
2024-07-08 12:25:56 +00:00
|
|
|
|
2024-08-14 09:57:27 +00:00
|
|
|
return processed_glossary.pairs().map(((key, entry)) => (
|
2024-08-12 16:09:14 +00:00
|
|
|
key: key,
|
2024-08-14 09:57:27 +00:00
|
|
|
short: entry.short,
|
2024-08-12 16:09:14 +00:00
|
|
|
long: eval(entry.at("long", default: ""), mode: "markup"),
|
|
|
|
desc: eval(entry.at("desc", default: ""), mode: "markup"),
|
|
|
|
group: entry.at("group", default: ""),
|
|
|
|
))
|
|
|
|
}
|