From 9c354f5e6b5c59521e36ec9ad3d7efb72da45a99 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sun, 11 Jul 2021 20:29:34 +1000 Subject: [PATCH] drop the cloze-in-basic check for now Unfortunately a popular note taking tool has been misusing cloze markers in its deck exports. We may want to add this back in the future, but we'll probably want to start by warning users, to give people time to adjust. --- rslib/src/notetype/mod.rs | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/rslib/src/notetype/mod.rs b/rslib/src/notetype/mod.rs index 178fb66cc..1220372b3 100644 --- a/rslib/src/notetype/mod.rs +++ b/rslib/src/notetype/mod.rs @@ -382,23 +382,15 @@ impl Notetype { }) } - fn ensure_cloze_if_and_only_if_cloze_notetype( + fn ensure_cloze_if_cloze_notetype( &self, parsed_templates: &[(Option, Option)], ) -> Result<()> { - if self.is_cloze() { - if missing_cloze_filter(parsed_templates) { - return Err(AnkiError::TemplateSaveError(TemplateSaveError { - notetype: self.name.clone(), - ordinal: 0, - details: TemplateSaveErrorDetails::MissingCloze, - })); - } - } else if let Some(i) = find_cloze_filter(parsed_templates) { + if self.is_cloze() && missing_cloze_filter(parsed_templates) { return Err(AnkiError::TemplateSaveError(TemplateSaveError { notetype: self.name.clone(), - ordinal: i, - details: TemplateSaveErrorDetails::ExtraneousCloze, + ordinal: 0, + details: TemplateSaveErrorDetails::MissingCloze, })); } Ok(()) @@ -460,7 +452,7 @@ impl Notetype { self.config.reqs = reqs; self.ensure_template_fronts_unique()?; self.ensure_valid_parsed_templates(&parsed_templates)?; - self.ensure_cloze_if_and_only_if_cloze_notetype(&parsed_templates)?; + self.ensure_cloze_if_cloze_notetype(&parsed_templates)?; Ok(()) } @@ -575,19 +567,6 @@ fn missing_cloze_filter( .map_or(true, |t| !has_cloze(&t.0) || !has_cloze(&t.1)) } -/// Return the index of the first tuple with a cloze field on either template. -fn find_cloze_filter( - parsed_templates: &[(Option, Option)], -) -> Option { - parsed_templates.iter().enumerate().find_map(|(i, t)| { - if has_cloze(&t.0) || has_cloze(&t.1) { - Some(i) - } else { - None - } - }) -} - /// True if the template is non-empty and has a cloze field. fn has_cloze(template: &Option) -> bool { template