mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
fix type:cloze, and remove misleading comments
This commit is contained in:
parent
afe391c18b
commit
5a9af48178
2 changed files with 23 additions and 12 deletions
|
@ -118,7 +118,7 @@ def apply_field_filters(
|
|||
field_name: str, field_text: str, fields: Dict[str, str], filters: List[str]
|
||||
) -> str:
|
||||
"""Apply filters to field text, returning modified text."""
|
||||
_sort_filters(filters)
|
||||
filters = _adjust_filters(filters)
|
||||
|
||||
for filter in filters:
|
||||
if "-" in filter:
|
||||
|
@ -137,15 +137,11 @@ def apply_field_filters(
|
|||
return field_text
|
||||
|
||||
|
||||
def _sort_filters(filters: List[str]):
|
||||
"Mutate the list of filters into the correct order."
|
||||
# Since 'text:' and other mods can affect html on which Anki relies to
|
||||
# process clozes, we need to make sure clozes are always
|
||||
# treated after all the other mods, regardless of how they're specified
|
||||
# in the template, so that {{cloze:text: == {{text:cloze:
|
||||
# For type:, we return directly since no other mod than cloze (or other
|
||||
# pre-defined mods) can be present and those are treated separately
|
||||
filters.sort(key=lambda s: not s == "type")
|
||||
def _adjust_filters(filters: List[str]) -> List[str]:
|
||||
"Handle the type:cloze: special case."
|
||||
if filters == ["cloze", "type"]:
|
||||
filters = ["type-cloze"]
|
||||
return filters
|
||||
|
||||
|
||||
# Cloze filter
|
||||
|
@ -344,9 +340,12 @@ def text_filter(txt: str, *args) -> str:
|
|||
return stripHTML(txt)
|
||||
|
||||
|
||||
def type_answer_filter(txt: str, args, context, tag: str, dummy) -> str:
|
||||
def type_answer_filter(txt: str, filter_args: str, context, tag: str, dummy) -> str:
|
||||
# convert it to [[type:...]] for the gui code to process
|
||||
return "[[type:%s]]" % tag
|
||||
if filter_args:
|
||||
return f"[[type:{filter_args}:{tag}]]"
|
||||
else:
|
||||
return f"[[type:{tag}]]"
|
||||
|
||||
|
||||
addHook("fmod_text", text_filter)
|
||||
|
|
|
@ -220,6 +220,18 @@ def test_cloze_mathjax():
|
|||
)
|
||||
|
||||
|
||||
def test_typecloze():
|
||||
d = getEmptyCol()
|
||||
m = d.models.byName("Cloze")
|
||||
d.models.setCurrent(m)
|
||||
m["tmpls"][0]["qfmt"] = "{{type:cloze:Text}}"
|
||||
d.models.save(m)
|
||||
f = d.newNote()
|
||||
f["Text"] = "hello {{c1::world}}"
|
||||
d.addNote(f)
|
||||
assert "[[type:cloze:Text]]" in f.cards()[0].q()
|
||||
|
||||
|
||||
def test_chained_mods():
|
||||
d = getEmptyCol()
|
||||
d.models.setCurrent(d.models.byName("Cloze"))
|
||||
|
|
Loading…
Reference in a new issue