feat(glossy): use @term[supplement] to override term display
If you want to completely override how a term is displayed, you can pass content in via the square brackets on the term's reference. For example, a term @www which might normally display as "worldwide web (WWW)" or something similar, could instead display as FOOBAR by using @www[FOOBAR].
This commit is contained in:
3 files changed
+44
-4
No files matched your search
+11
-4
@@ -210,7 +210,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, format-term: function, show-term: function, term-links: true) = {
|
#let __gls(key, modifiers: array, format-term: function, show-term: function, term-links: true, display-text: none) = {
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Check for illegal modifier combinations
|
// Check for illegal modifier combinations
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -355,8 +355,14 @@
|
|||||||
let long-form = pluralize_term(entry.long, entry.longplural) // `none` safe here
|
let long-form = pluralize_term(entry.long, entry.longplural) // `none` safe here
|
||||||
|
|
||||||
// Apply format-term() to get the term
|
// Apply format-term() to get the term
|
||||||
let formatted-term = format-term(mode, short-form, long-form)
|
let formatted-term = if display-text != none and display-text != auto {
|
||||||
if type(formatted-term) != str {
|
// Display text was overriden by user, just accept it (string or content)
|
||||||
|
display-text
|
||||||
|
} else {
|
||||||
|
// Normal display (ie no override from user)
|
||||||
|
format-term(mode, short-form, long-form)
|
||||||
|
}
|
||||||
|
if "cap" in modifiers and type(formatted-term) != str {
|
||||||
// This is because we still need to capitalize the term, and we cannot do
|
// This is because we still need to capitalize the term, and we cannot do
|
||||||
// that with content, thus requiring a string here.
|
// that with content, thus requiring a string here.
|
||||||
// TODO: consider if we want to capitalize *before* this. First intuition is
|
// TODO: consider if we want to capitalize *before* this. First intuition is
|
||||||
@@ -526,6 +532,7 @@
|
|||||||
// Set up reference handling for glossary terms
|
// Set up reference handling for glossary terms
|
||||||
show ref: r => {
|
show ref: r => {
|
||||||
let (raw_key, ..raw_modifiers) = str(r.target).split(":")
|
let (raw_key, ..raw_modifiers) = str(r.target).split(":")
|
||||||
|
let supplement = r.supplement // used for term display overrides
|
||||||
|
|
||||||
// Determine if we need to swap the key and first modifier.
|
// Determine if we need to swap the key and first modifier.
|
||||||
// Conditions for swapping:
|
// Conditions for swapping:
|
||||||
@@ -545,7 +552,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), format-term: format-term, show-term: show-term, term-links: term-links)
|
__gls(key, modifiers: modifiers.map(lower), format-term: format-term, show-term: show-term, term-links: term-links, display-text: supplement)
|
||||||
} else {
|
} else {
|
||||||
// Not one of ours, so just pass it through
|
// Not one of ours, so just pass it through
|
||||||
r
|
r
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 126 KiB |
@@ -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")
|
||||||
|
|
||||||
|
= Overriding term display
|
||||||
|
|
||||||
|
Here is @html[HTML being overidden].
|
||||||
|
|
||||||
|
Here is @css[] (blank).
|
||||||
|
|
||||||
|
Here is @tps[TPS with #emph("content")]
|
||||||
|
|
||||||
|
#glossary()
|
||||||
Reference in new issue
Block a user