From daf5f68fd5ff3684f372b91f55ab085b19a2f736 Mon Sep 17 00:00:00 2001 From: Abdo Date: Wed, 10 Jul 2024 15:59:31 +0300 Subject: [PATCH] Limit cloze nesting level (#3264) * Limit cloze nesting level * Break cloze rendering at a lower limit --- rslib/src/cloze.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/rslib/src/cloze.rs b/rslib/src/cloze.rs index 5aab2e83f..1fb97ed85 100644 --- a/rslib/src/cloze.rs +++ b/rslib/src/cloze.rs @@ -158,11 +158,15 @@ fn parse_text_with_clozes(text: &str) -> Vec> { let mut output = vec![]; for token in tokenize(text) { match token { - Token::OpenCloze(ordinal) => open_clozes.push(ExtractedCloze { - ordinal, - nodes: Vec::with_capacity(1), // common case - hint: None, - }), + 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