Make terms clickable links to glossary list
This commit is contained in:
1 parent
80eeb9240c
commit
2b6debb7d1
1 file changed
+13
-5
+13
-5
@@ -155,10 +155,10 @@
|
|||||||
// key (string): The glossary entry key
|
// key (string): The glossary entry key
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
// boolean: If the entry is visible in the glossary
|
// boolean: If the term is visible in the glossary (and the label is unique)
|
||||||
//
|
//
|
||||||
#let __has_glossary_entry(key) = {
|
#let __has_glossary_entry(key) = {
|
||||||
query(<glossary>).len() > 0 and query(selector(label(key)).after(<glossary>)).len() > 0
|
query(<glossary>).len() > 0 and query(selector(label(key)).after(<glossary>)).len() == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Renders a glossary term with various formatting options.
|
// Renders a glossary term with various formatting options.
|
||||||
@@ -174,6 +174,7 @@
|
|||||||
// - "def" or "desc": Show the term's description instead of its name.
|
// - "def" or "desc": Show the term's description instead of its name.
|
||||||
// - "a" or "an": Prepend an article, chosen from the entry (short or long form).
|
// - "a" or "an": Prepend an article, chosen from the entry (short or long form).
|
||||||
// show-term (function): A function that renders the chosen term.
|
// show-term (function): A function that renders the chosen term.
|
||||||
|
// term-links (boolean): If terms should be clickable links leading to glossary
|
||||||
//
|
//
|
||||||
// Behavior:
|
// Behavior:
|
||||||
// - Without modifiers, the first use of a term shows "Long form (short form)",
|
// - Without modifiers, the first use of a term shows "Long form (short form)",
|
||||||
@@ -186,7 +187,7 @@
|
|||||||
// content: The fully formatted term, including optional article, capitalization,
|
// content: The fully formatted term, including optional article, capitalization,
|
||||||
// usage tracking metadata, and the chosen form (short, long, or both).
|
// usage tracking metadata, and the chosen form (short, long, or both).
|
||||||
//
|
//
|
||||||
#let __gls(key, modifiers: array, show-term: function) = {
|
#let __gls(key, modifiers: array, show-term: function, term-links: true) = {
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Check for illegal modifier combinations
|
// Check for illegal modifier combinations
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -343,7 +344,12 @@
|
|||||||
// Construct and return the final output
|
// Construct and return the final output
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
context {
|
context {
|
||||||
[#article#show-term(term)#metadata(term)#__term_label(key)]
|
let text = if term-links and __has_glossary_entry(key) {
|
||||||
|
link(label(key), term)
|
||||||
|
} else {
|
||||||
|
term
|
||||||
|
}
|
||||||
|
[#article#show-term(text)#metadata(term)#__term_label(key)]
|
||||||
// |^^^^^^^|^^^^^^^^^ |^^^^^^^^ |^^^^^^^^^^^^
|
// |^^^^^^^|^^^^^^^^^ |^^^^^^^^ |^^^^^^^^^^^^
|
||||||
// \_art. | | |
|
// \_art. | | |
|
||||||
// \_ apply user formatting function to the term
|
// \_ apply user formatting function to the term
|
||||||
@@ -395,6 +401,7 @@
|
|||||||
// - values are entry dictionaries containing term details
|
// - values are entry dictionaries containing term details
|
||||||
// show-term ((content) => content): Optional function to customize term rendering
|
// show-term ((content) => content): Optional function to customize term rendering
|
||||||
// Default: Returns term content unchanged
|
// Default: Returns term content unchanged
|
||||||
|
// term-links (boolean): If terms should be clickable links leading to glossary
|
||||||
// body (content): Document content to process
|
// body (content): Document content to process
|
||||||
//
|
//
|
||||||
// Returns:
|
// Returns:
|
||||||
@@ -406,6 +413,7 @@
|
|||||||
#let init-glossary(
|
#let init-glossary(
|
||||||
entries,
|
entries,
|
||||||
show-term: (term-body) => term-body,
|
show-term: (term-body) => term-body,
|
||||||
|
term-links: true,
|
||||||
body
|
body
|
||||||
) = context {
|
) = context {
|
||||||
// Type checking
|
// Type checking
|
||||||
@@ -449,7 +457,7 @@
|
|||||||
// Now see if this is an actual glossary term key
|
// Now see if this is an actual glossary term key
|
||||||
if __has_entry(key) {
|
if __has_entry(key) {
|
||||||
// Found in dictionary, render via __gls()
|
// Found in dictionary, render via __gls()
|
||||||
__gls(key, modifiers: modifiers.map(lower), show-term: show-term)
|
__gls(key, modifiers: modifiers.map(lower), show-term: show-term, term-links: term-links)
|
||||||
} else {
|
} else {
|
||||||
// Not one of ours, so just pass it through
|
// Not one of ours, so just pass it through
|
||||||
r
|
r
|
||||||
|
|||||||
Reference in new issue
Block a user