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:
a.r 2024-10-26 11:58:52 +02:00 committed by GitHub
parent e4eaaa57ab
commit 0513940305
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -31,12 +31,12 @@ pub(crate) fn apply_filters<'a>(
let mut text: Cow<str> = text.into();
// type:cloze & type:nc are handled specially
let filters = if filters == ["cloze", "type"] {
&["type-cloze"]
} else if filters == ["nc", "type"] {
&["type-nc"]
} else {
filters
// other type: are passed as the default one
let filters = match filters {
["cloze", "type"] => &["type-cloze"],
["nc", "type"] => &["type-nc"],
[.., "type"] => &["type"],
_ => filters,
};
for (idx, &filter_name) in filters.iter().enumerate() {
@ -259,6 +259,10 @@ field</a>
apply_filters("ignored", &["nc", "type"], "Text", &ctx),
("[[type:nc:Text]]".into(), vec![])
);
assert_eq!(
apply_filters("ignored", &["some", "unknown", "type"], "Text", &ctx),
("[[type:Text]]".into(), vec![])
);
}
#[test]