|
241 | 241 | __glossary_reset_locations.update(x => x + (loc,)) |
242 | 242 | } |
243 | 243 |
|
| 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 | + |
244 | 271 | #let default-capitalize(text) = { |
245 | 272 | if text == none { return text } |
246 | 273 | if type(text) == content { |
|
1254 | 1281 | // The description of the entry |
1255 | 1282 | #let default-print-description(entry) = entry.at(DESCRIPTION) |
1256 | 1283 |
|
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"). |
1265 | 1292 | #let default-print-title(entry) = { |
1266 | 1293 | let caption = [] |
1267 | 1294 | 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")) |
1269 | 1297 | 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) |
1271 | 1299 | } else if has-long(entry) { |
1272 | | - caption += txt(entry.at(LONG)) |
| 1300 | + caption += txt(long-val) |
1273 | 1301 | } else { |
1274 | | - caption += txt(emph(entry.at(SHORT))) |
| 1302 | + caption += txt(emph(short-val)) |
1275 | 1303 | } |
1276 | 1304 | return caption |
1277 | 1305 | } |
|
0 commit comments