Skip to content

Commit

Permalink
Add circled number for numbering
Browse files Browse the repository at this point in the history
  • Loading branch information
Enter-tainer committed May 1, 2024
1 parent 2c678e8 commit 2de7fb2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions crates/typst/src/model/numbering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ pub enum NumberingKind {
KatakanaIroha,
KoreanJamo,
KoreanSyllable,
CircledNumber,
DoubleCircledNumber,
}

impl NumberingKind {
Expand All @@ -280,6 +282,8 @@ impl NumberingKind {
'イ' => NumberingKind::KatakanaIroha,
'ㄱ' => NumberingKind::KoreanJamo,
'가' => NumberingKind::KoreanSyllable,
'①' => NumberingKind::CircledNumber,
'⓵' => NumberingKind::DoubleCircledNumber,
_ => return None,
})
}
Expand All @@ -300,6 +304,8 @@ impl NumberingKind {
Self::KatakanaIroha => 'イ',
Self::KoreanJamo => 'ㄱ',
Self::KoreanSyllable => '가',
Self::CircledNumber => '①',
Self::DoubleCircledNumber => '⓵',
}
}

Expand Down Expand Up @@ -507,6 +513,22 @@ impl NumberingKind {
},
n,
),
Self::CircledNumber => zeroless::<50>(
|x| {
[
'①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩', '⑪', '⑫', '⑬',
'⑭', '⑮', '⑯', '⑰', '⑱', '⑲', '⑳', '㉑', '㉒', '㉓', '㉔', '㉕',
'㉖', '㉗', '㉘', '㉙', '㉚', '㉛', '㉜', '㉝', '㉞', '㉟', '㊱',
'㊲', '㊳', '㊴', '㊵', '㊶', '㊷', '㊸', '㊹', '㊺', '㊻', '㊼',
'㊽', '㊾', '㊿',
][x]
},
n,
),
Self::DoubleCircledNumber => zeroless::<10>(
|x| ['⓵', '⓶', '⓷', '⓸', '⓹', '⓺', '⓻', '⓼', '⓽', '⓾'][x],
n,
),
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/suite/model/numbering.typ
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,11 @@
--- numbering-negative ---
// Error: 17-19 number must be at least zero
#numbering("1", -1)

--- numbering-circled-number ---
#assert(numbering("①", 1) == "①")
#assert(numbering("①", 50) == "㊿")

--- numbering-double-circled-number ---
#assert(numbering("⓵", 1) == "⓵")
#assert(numbering("⓵", 10) == "⓾")

0 comments on commit 2de7fb2

Please sign in to comment.