fix(glossy): avoid duplicate key labels

This commit is contained in:
BurningKarl authored and Stephen Waits committed 2025-04-03 15:16:09 -07:00
1 parent 8e8723b8d1
commit 797fc68857
1 file changed
+22 -6
+22 -6
View File
@@ -8,6 +8,7 @@
#let __gloss_label_prefix = "__gloss:"
#let __gloss_first_use_counter_postfix = ":first-use-count"
#let __gloss_entry_postfix = ":entry"
// Normalizes a dictionary entry by ensuring all required and optional keys exist
// with appropriate default values.
@@ -122,6 +123,18 @@
label(__gloss_label_prefix + key)
}
// Creates a label object for the entry in the glossary.
//
// Parameters:
// key (string): The glossary entry key
//
// Returns:
// label: A Typst label object for the term usage
//
#let __entry_label(key) = {
label(__gloss_label_prefix + key + __gloss_entry_postfix)
}
// Updates the term usage in the glossary state.
//
// Parameters:
@@ -179,7 +192,7 @@
// boolean: If the term is visible in the glossary (and the label is unique)
//
#let __has_glossary_entry(key) = {
query(<glossary>).len() > 0 and query(selector(label(key)).after(<glossary>)).len() == 1
query(__entry_label(key)).len() > 0
}
// Renders a glossary term with various formatting options.
@@ -377,6 +390,11 @@
// Construct and return the final output
// ---------------------------------------------------------------------------
context {
let linked-term = if term-links and query(__entry_label(key)).len() > 0 {
link(__entry_label(key), term)
} else {
term
}
// Figure out our label (unless not wanted)
let term-label = if wants_reference {
__term_label(key)
@@ -523,10 +541,8 @@
// Process and store each glossary entry
for (key, entry) in entries {
__add_entry(key, __normalize_entry(key, entry))
// Create placeholder labels for autocompletion (if not already present)
context if not __has_glossary_entry(key) [
#metadata(key)#label(key)
]
// Create placeholder labels for autocompletion
[#metadata(key)#label(key)]
}
// Set up reference handling for glossary terms
@@ -655,7 +671,7 @@
short: entry.at("short"),
long: entry.at("long"),
description: entry.at("description"),
label: [#metadata(key)#label(key)],
label: [#metadata(key)#__entry_label(key)],
pages: __create_backlinks(key)
))
}