feat(glossy): adds hide/hidden modifier to suppress term display

There are cases where you might want a term referenced (ie from the
Glossary/Index), but don't want to display it. New modifiers
`hide`||`hidden` do exactly that.
This commit is contained in:
swaits committed 2025-04-03 08:37:28 -07:00
1 parent 966a89687a
commit 5957432d5d
3 files changed
+73 -18

No files matched your search

+40 -18
View File
@@ -194,6 +194,8 @@
// - "long": Show only the long form. // - "long": Show only the long form.
// - "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).
// - "hide" or "hidden": Use term (for the sake of the glossary/index),
// but don't display it.
// 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 // term-links (boolean): If terms should be clickable links leading to glossary
// //
@@ -218,6 +220,9 @@
if ("a" in modifiers or "an" in modifiers) and ("pl" in modifiers) { if ("a" in modifiers or "an" in modifiers) and ("pl" in modifiers) {
panic("Cannot use 'a'/'an' and 'pl' together.") panic("Cannot use 'a'/'an' and 'pl' together.")
} }
if ("hidden" in modifiers or "hide" in modifiers) and modifiers.len() > 1{
panic("Cannot use 'hide'/'hidden' with other modifiers.")
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Retrieve the glossary entry and its label // Retrieve the glossary entry and its label
@@ -297,8 +302,11 @@
// If no explicit mode is given, the default behavior is: // If no explicit mode is given, the default behavior is:
// - On first use and if a long form exists, "both". // - On first use and if a long form exists, "both".
// - Otherwise, "short". // - Otherwise, "short".
let determine_mode = (wants_both, wants_long, wants_short, is_first_use, long_available) => { let determine_mode = (wants_both, wants_long, wants_short, is_first_use, long_available, wants_hidden) => {
if wants_both { if wants_hidden {
// If it's hidden, nothing else matters
"hidden"
} else if wants_both {
// Explicit request for "both": // Explicit request for "both":
// If a long form exists, use "both", otherwise fall back to "short". // If a long form exists, use "both", otherwise fall back to "short".
if long_available { if long_available {
@@ -336,10 +344,11 @@
let wants_both = "both" in modifiers let wants_both = "both" in modifiers
let wants_long = "long" in modifiers let wants_long = "long" in modifiers
let wants_short = "short" in modifiers let wants_short = "short" in modifiers
let wants_hidden = ("hidden" in modifiers or "hide" in modifiers)
let long_available = entry.long != none let long_available = entry.long != none
// Determine mode using the helper function // Determine mode using the helper function
let mode = determine_mode(wants_both, wants_long, wants_short, is_first_use, long_available) let mode = determine_mode(wants_both, wants_long, wants_short, is_first_use, long_available, wants_hidden)
// Pluralize (if requested) // Pluralize (if requested)
let short-form = pluralize_term(entry.short, entry.plural) let short-form = pluralize_term(entry.short, entry.plural)
@@ -362,25 +371,38 @@
// Construct and return the final output // Construct and return the final output
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
context { context {
let linked-term = if term-links and __has_glossary_entry(key) { // Figure out our label (unless not wanted)
link(label(key), term) let term-label = if wants_reference {
} else {
term
}
let term-label = if wants_reference {
__term_label(key) __term_label(key)
} else { } else {
[] []
} }
[#article#show-term(linked-term)#metadata(term)#term-label]
// |^^^^^^^|^^^^^^^^^ |^^^^^^^^ |^^^^^^^^^^^^ // Create the output content
// \_art. | | | if mode == "hidden" {
// \_ apply user formatting function to the term // just put the metadata+label out there
// | | [#metadata("hidden term")#term-label]
// \_ metadata lets us label (ie makes it "labelable") } else {
// | // normal term display (ie not hidden)
// \_ i.e. <__gloss:key>, etc.
// for backlink from glossary // create the forward link, if watned
let linked-term = if term-links and __has_glossary_entry(key) {
link(label(key), term)
} else {
term
}
// and the final content
[#article#show-term(linked-term)#metadata(term)#term-label]
// |^^^^^|^^^^^^^^^ |^^^^^^^^ |^^^^^^^^^^^^
// \_art.| | |
// \_ apply user formatting function to the term
// | |
// \_ metadata lets us label (ie makes it "labelable")
// |
// \_ i.e. <__gloss:key>, etc.
// for backlink from glossary
}
} }
} }
Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

+33
View File
@@ -0,0 +1,33 @@
#import "/lib.typ": *
#let myGlossary = (
html: (
short: "HTML",
long: "Hypertext Markup Language",
description: "A standard language for creating web pages",
group: "Web"),
css: (
short: "CSS",
long: "Cascading Style Sheets",
description: "A language used for describing the presentation of a document",
group: "Web"),
tps: (
short: "TPS",
long: "test procedure specification",
description: "A document on how to run all the test procedures"),
unused: "Unused term, which shouldn't print in the glossary."
)
#show: init-glossary.with(myGlossary)
#set page(height: auto, width: 6.5in, margin: 1em, numbering: "1")
= Hiding terms
Here's a hidden term: @html:hide
Here's another hidden term: @css:hidden
And here's a shown term: @tps
#glossary()