Fix field check for cloze conditional (#1975)
This commit is contained in:
parent
5f9fa51026
commit
b9fd6688d2
@ -502,9 +502,7 @@ impl<'a> RenderContext<'a> {
|
|||||||
fn evaluate_conditional(&self, key: &str, negated: bool) -> TemplateResult<bool> {
|
fn evaluate_conditional(&self, key: &str, negated: bool) -> TemplateResult<bool> {
|
||||||
if self.nonempty_fields.contains(key) {
|
if self.nonempty_fields.contains(key) {
|
||||||
Ok(true ^ negated)
|
Ok(true ^ negated)
|
||||||
} else if self.fields.contains_key(key)
|
} else if self.fields.contains_key(key) || is_cloze_conditional(key) {
|
||||||
|| (key.starts_with('c') && key[1..].parse::<u32>().is_ok())
|
|
||||||
{
|
|
||||||
Ok(false ^ negated)
|
Ok(false ^ negated)
|
||||||
} else {
|
} else {
|
||||||
let prefix = if negated { "^" } else { "#" };
|
let prefix = if negated { "^" } else { "#" };
|
||||||
@ -828,7 +826,7 @@ fn find_field_references<'a>(
|
|||||||
}
|
}
|
||||||
ParsedNode::Conditional { key, children }
|
ParsedNode::Conditional { key, children }
|
||||||
| ParsedNode::NegatedConditional { key, children } => {
|
| ParsedNode::NegatedConditional { key, children } => {
|
||||||
if with_conditionals {
|
if with_conditionals && !is_cloze_conditional(key) {
|
||||||
fields.insert(key);
|
fields.insert(key);
|
||||||
}
|
}
|
||||||
find_field_references(children, fields, cloze_only, with_conditionals);
|
find_field_references(children, fields, cloze_only, with_conditionals);
|
||||||
@ -837,6 +835,11 @@ fn find_field_references<'a>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_cloze_conditional(key: &str) -> bool {
|
||||||
|
key.strip_prefix('c')
|
||||||
|
.map_or(false, |s| s.parse::<u32>().is_ok())
|
||||||
|
}
|
||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
//---------------------------------------
|
//---------------------------------------
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user