Skip to content

Commit

Permalink
fix(glossy): use codepoints (not bytes!) in article code
Browse files Browse the repository at this point in the history
Fixes [#18](#18)
  • Loading branch information
swaits committed Dec 20, 2024
1 parent c37c675 commit 842166c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
2 changes: 1 addition & 1 deletion glossy/src/gloss.typ
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@
// 1. create array of tuples with (lower [if ignore-case], entry)
.map(e => { if ignore-case { (lower(e.short), e) } else { (e.short, e) } })
// 2. sort the tuples (by first element then second)
.sorted(key: t => t.first())
.sorted() // NOTE: sorted() is NOT language-aware
// 3. strip away the tuple's first element, leaving an array of entries
.map(t => t.last())

Expand Down
4 changes: 2 additions & 2 deletions glossy/src/utils.typ
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@

if is_acronym {
// Use acronym rules
let first_char = upper_word.slice(0,1)
let first_char = upper_word.codepoints().slice(0,1).first()
if acronym_vowels.contains(first_char) {
"an"
} else {
"a"
}
} else {
// Non-acronym rules
let first_char = lower_word.slice(0,1)
let first_char = lower_word.codepoints().slice(0,1).first()

// Special cases for words matching a set of known 'silent h' prefixes
let silent_h_words = (
Expand Down
23 changes: 23 additions & 0 deletions glossy/tests/utf-handling/glossary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
cab:
short: "cab"
long: "taxi cab"

coo:
short: "COO"
long: "Chief Operations Officer"

cuckoo:
short: "cuckoo"
long: "really crazy"

delta:
short: "delta"
long: "difference between two values"

dal:
short: "DAL"
long: "Delta Airlines"

čr:
short: "ČR"
long: "Česká Republika"
Binary file added glossy/tests/utf-handling/ref/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions glossy/tests/utf-handling/test.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#import "/lib.typ":*

#set text(lang: "cs", region: "CZ")

#show: init-glossary.with(yaml("glossary.yml"))
#glossary(ignore-case: true)

#line(length: 20em)

@čr

@cab

@coo

@cuckoo

@delta

@dal

0 comments on commit 842166c

Please sign in to comment.