fix: cloze_numbers_in_string treating {{c0::}} as valid (#3059)

* fix: cloze_numbers_in_string treating `{{c0::}}` as valid

* Update rslib/src/cloze.rs

Co-authored-by: Abdo <abdo@abdnh.net>

---------

Co-authored-by: Abdo <abdo@abdnh.net>
This commit is contained in:
Brayan Oliveira 2024-03-12 05:51:13 -03:00 committed by GitHub
parent 057733d02e
commit 1bd6d2883e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -417,7 +417,7 @@ pub fn cloze_numbers_in_string(html: &str) -> HashSet<u16> {
fn add_cloze_numbers_in_text_with_clozes(nodes: &[TextOrCloze], set: &mut HashSet<u16>) {
for node in nodes {
if let TextOrCloze::Cloze(cloze) = node {
if !(cloze.image_occlusion().is_some() && cloze.ordinal == 0) {
if cloze.ordinal != 0 {
set.insert(cloze.ordinal);
add_cloze_numbers_in_text_with_clozes(&cloze.nodes, set);
}
@ -471,6 +471,10 @@ mod test {
cloze_numbers_in_string("{{c2::te}}{{c1::s}}t{{"),
vec![1, 2].into_iter().collect::<HashSet<u16>>()
);
assert_eq!(
cloze_numbers_in_string("{{c0::te}}s{{c2::t}}s"),
vec![2].into_iter().collect::<HashSet<u16>>()
);
assert_eq!(
expand_clozes_to_reveal_latex("{{c1::foo}} {{c2::bar::baz}}"),