mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -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):
|
def filesInStr(self, mid, string, includeRemote=False):
|
||||||
l = []
|
l = []
|
||||||
# convert latex first
|
|
||||||
model = self.col.models.get(mid)
|
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)
|
string = mungeQA(string, None, None, model, None, self.col)
|
||||||
# extract filenames
|
# extract filenames
|
||||||
for reg in self.regexps:
|
for reg in self.regexps:
|
||||||
|
@ -119,6 +127,24 @@ If the same name exists, compare checksums."""
|
||||||
l.append(fname)
|
l.append(fname)
|
||||||
return l
|
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):
|
def transformNames(self, txt, func):
|
||||||
for reg in self.regexps:
|
for reg in self.regexps:
|
||||||
txt = re.sub(reg, func, txt)
|
txt = re.sub(reg, func, txt)
|
||||||
|
|
Loading…
Reference in a new issue