Skip to content

Commit 8de6208

Browse files
committed
feat(typst-community/glossarium/#188): adjust default styling in glossary so that applied styling on glossary entry is removed
1 parent f58cb27 commit 8de6208

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

themes/default.typ

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,33 @@
241241
__glossary_reset_locations.update(x => x + (loc,))
242242
}
243243

244+
/// Extracts raw text from Typst content by stripping away formatting.
245+
///
246+
/// This is useful when you need the "letters only" version of a title—for
247+
/// example, to use a heading name inside a PDF bookmark where bold or
248+
/// italics aren't allowed.
249+
///
250+
/// - object (any): The item to extract text from (can be a string,
251+
/// formatted content like *Bold*, or a list of items).
252+
/// -> return: A plain string containing only the text found in the object.
253+
#let get-plain-text(object) = {
254+
if object == none {
255+
""
256+
}
257+
258+
if type(object) == str {
259+
object
260+
} else if object.has("text") {
261+
object.text
262+
} else if object.has("children") {
263+
object.children.map(get-plain-text).join("")
264+
} else if object.has("body") {
265+
get-plain-text(object.body)
266+
} else {
267+
""
268+
}
269+
}
270+
244271
#let default-capitalize(text) = {
245272
if text == none { return text }
246273
if type(text) == content {
@@ -1254,24 +1281,25 @@
12541281
// The description of the entry
12551282
#let default-print-description(entry) = entry.at(DESCRIPTION)
12561283

1257-
// default-print-title(entry) -> content
1258-
// Print the title of the entry
1259-
//
1260-
// # Arguments
1261-
// entry (dictionary): the entry
1262-
//
1263-
// # Returns
1264-
// The title of the entry
1284+
/// Formats and displays the title of a glossary entry.
1285+
///
1286+
/// This function decides how the "short" (acronym) and "long" (full name)
1287+
/// versions of a term appear in your glossary list.
1288+
///
1289+
/// - entry (dictionary): A collection containing the 'short' and 'long'
1290+
/// definitions for a term.
1291+
/// -> content: Returns the formatted text (e.g., "CPU -- Central Processing Unit").
12651292
#let default-print-title(entry) = {
12661293
let caption = []
12671294
let txt = strong.with(delta: 200)
1268-
1295+
let short-val = plain-text(entry.at("short"))
1296+
let long-val = plain-text(entry.at("long"))
12691297
if has-long(entry) and has-short(entry) {
1270-
caption += txt(emph(entry.at(SHORT)) + [ -- ] + entry.at(LONG))
1298+
caption += txt(emph(short-val) + [ -- ] + long-val)
12711299
} else if has-long(entry) {
1272-
caption += txt(entry.at(LONG))
1300+
caption += txt(long-val)
12731301
} else {
1274-
caption += txt(emph(entry.at(SHORT)))
1302+
caption += txt(emph(short-val))
12751303
}
12761304
return caption
12771305
}

0 commit comments

Comments
 (0)