mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
template_filters: make {{type:}} forwards compatible (#3525)
Make Anki treat {{type:unknown:field}} field replacements as {{type:field}} instead of {{field}}. The previous behavior was seriously inconvenient for several reasons, including: * Updated client aren't all released at the same time, causing an unavoidable mismatch period. Now it causes the least friction. * Devs couldn't readily test new in-dev variants without breaking/inconveniencing their own mobile experience. * Some users will have (potentially perpetually) outdated Anki clients and likely complain, wasting both dev & deck creator time. This way users always get to type and especially: The front side will always render as intended.
This commit is contained in:
parent
e4eaaa57ab
commit
0513940305
1 changed files with 10 additions and 6 deletions
|
@ -31,12 +31,12 @@ pub(crate) fn apply_filters<'a>(
|
||||||
let mut text: Cow<str> = text.into();
|
let mut text: Cow<str> = text.into();
|
||||||
|
|
||||||
// type:cloze & type:nc are handled specially
|
// type:cloze & type:nc are handled specially
|
||||||
let filters = if filters == ["cloze", "type"] {
|
// other type: are passed as the default one
|
||||||
&["type-cloze"]
|
let filters = match filters {
|
||||||
} else if filters == ["nc", "type"] {
|
["cloze", "type"] => &["type-cloze"],
|
||||||
&["type-nc"]
|
["nc", "type"] => &["type-nc"],
|
||||||
} else {
|
[.., "type"] => &["type"],
|
||||||
filters
|
_ => filters,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (idx, &filter_name) in filters.iter().enumerate() {
|
for (idx, &filter_name) in filters.iter().enumerate() {
|
||||||
|
@ -259,6 +259,10 @@ field</a>
|
||||||
apply_filters("ignored", &["nc", "type"], "Text", &ctx),
|
apply_filters("ignored", &["nc", "type"], "Text", &ctx),
|
||||||
("[[type:nc:Text]]".into(), vec![])
|
("[[type:nc:Text]]".into(), vec![])
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
apply_filters("ignored", &["some", "unknown", "type"], "Text", &ctx),
|
||||||
|
("[[type:Text]]".into(), vec![])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue