Limit cloze nesting level (#3264)

* Limit cloze nesting level

* Break cloze rendering at a lower limit
This commit is contained in:
Abdo 2024-07-10 15:59:31 +03:00 committed by GitHub
parent e985fec9c4
commit daf5f68fd5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -158,11 +158,15 @@ fn parse_text_with_clozes(text: &str) -> Vec<TextOrCloze<'_>> {
let mut output = vec![];
for token in tokenize(text) {
match token {
Token::OpenCloze(ordinal) => open_clozes.push(ExtractedCloze {
Token::OpenCloze(ordinal) => {
if open_clozes.len() < 3 {
open_clozes.push(ExtractedCloze {
ordinal,
nodes: Vec::with_capacity(1), // common case
hint: None,
}),
})
}
}
Token::Text(mut text) => {
if let Some(cloze) = open_clozes.last_mut() {
// extract hint if found