mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
properly generate clozed latex in unused media check (#775)
This commit is contained in:
parent
c681102476
commit
bf1af126b0
1 changed files with 34 additions and 8 deletions
|
@ -108,8 +108,16 @@ If the same name exists, compare checksums."""
|
|||
|
||||
def filesInStr(self, mid, string, includeRemote=False):
|
||||
l = []
|
||||
# convert latex first
|
||||
model = self.col.models.get(mid)
|
||||
strings = []
|
||||
if model['type'] == MODEL_CLOZE and "{{c" in string:
|
||||
# if the field has clozes in it, we'll need to expand the
|
||||
# possibilities so we can render latex
|
||||
strings = self._expandClozes(string)
|
||||
else:
|
||||
strings = [string]
|
||||
for string in strings:
|
||||
# handle latex
|
||||
string = mungeQA(string, None, None, model, None, self.col)
|
||||
# extract filenames
|
||||
for reg in self.regexps:
|
||||
|
@ -119,6 +127,24 @@ If the same name exists, compare checksums."""
|
|||
l.append(fname)
|
||||
return l
|
||||
|
||||
def _expandClozes(self, string):
|
||||
ords = set(re.findall("{{c(\d+)::.+?}}", string))
|
||||
strings = []
|
||||
from anki.template.template import clozeReg
|
||||
def qrepl(m):
|
||||
if m.group(3):
|
||||
return "[%s]" % m.group(3)
|
||||
else:
|
||||
return "[...]"
|
||||
def arepl(m):
|
||||
return m.group(1)
|
||||
for ord in ords:
|
||||
s = re.sub(clozeReg%ord, qrepl, string)
|
||||
s = re.sub(clozeReg%".+?", "\\1", s)
|
||||
strings.append(s)
|
||||
strings.append(re.sub(clozeReg%".+?", arepl, string))
|
||||
return strings
|
||||
|
||||
def transformNames(self, txt, func):
|
||||
for reg in self.regexps:
|
||||
txt = re.sub(reg, func, txt)
|
||||
|
|
Loading…
Reference in a new issue