问题
I am having two cards in my card type, which I created based on the cloze deletion type, by copying it.
If the position of my card is 1, than as described in the documentation, {{cloze:MyDataField}}
works, as I like. But if the position of the card is two, the cloze deletion extension seems to be disabled.
On my card on position two I only need to display the sentence, without the {{c1::word1}}
, ...., {{cN::wordN}}
tags but with the words, wrapped by those.
Is there maybe a way to create two cards using a close type in my card type's template? Or is there maybe a way to get the plain text of my fields so that I can parse it with JavaScript? Or can I maybe somehow just display the content of the field, ignoring {{c1
expressions, but displaying the content?
回答1:
It is possible to write an Anki add-on to do this, if you are familiar with Python 2. Cards compiled with a Desktop Anki with this add-on installed will work on AnkiWeb without displaying gibberish. Here is an (untested!) add-on that should register a special fmod
that allows you to write {{uncloze:fieldname}}
to get the plain text sans {{cn::
and }}
marks.
import re
from anki.hooks import addHook
from anki.template.template import Template
"""Adds support for the unclose Moustache tag.
Blame wizzwizz4 if this does / doesn't work.
Modified to work for <anki_version> by <your_name>."""
open_cloze_regex = re.compile(r"{{c\d+::")
def fmod_uncloze(txt, extra, context, tag, tag_name):
field_name = tag_name[8:] # Strip off "uncloze:"
field_content = Template("{{" + field_name + "}}", context).render()
return open_cloze_regex.sub("", field_content).replace("}}", "")
addHook("fmod_uncloze", fmod_uncloze)
Put this in a file in the Anki add-ons directory then restart Anki to install it.
Much of this code is from this answer.
来源:https://stackoverflow.com/questions/40333508/customizing-the-cloze-card-type-having-two-cards-in-a-card-type