mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
ensure we match on identical closing quote (#769)
This commit is contained in:
parent
c45525179b
commit
8f36841281
2 changed files with 11 additions and 8 deletions
|
@ -13,8 +13,9 @@ from anki.latex import mungeQA
|
|||
class MediaManager(object):
|
||||
|
||||
# other code depends on this order, so don't reorder
|
||||
regexps = ("(?i)(\[sound:([^]]+)\])",
|
||||
"(?i)(<img[^>]+src=[\"']?([^\"'>]+)[\"']?[^>]*>)")
|
||||
regexps = ("(?i)(\[sound:(?P<fname>[^]]+)\])",
|
||||
"(?i)(<img[^>]+src=(?P<str>[\"']?)"+
|
||||
"(?P<fname>[^>]+?)(?P=str)[^>]*>)")
|
||||
|
||||
def __init__(self, col, server):
|
||||
self.col = col
|
||||
|
@ -124,7 +125,8 @@ If the same name exists, compare checksums."""
|
|||
string = mungeQA(string, None, None, model, None, self.col)
|
||||
# extract filenames
|
||||
for reg in self.regexps:
|
||||
for (full, fname) in re.findall(reg, string):
|
||||
for match in re.finditer(reg, string):
|
||||
fname = match.group("fname")
|
||||
isLocal = not re.match("(https?|ftp)://", fname.lower())
|
||||
if isLocal or includeRemote:
|
||||
l.append(fname)
|
||||
|
@ -167,8 +169,8 @@ If the same name exists, compare checksums."""
|
|||
if isWin:
|
||||
return string
|
||||
def repl(match):
|
||||
tag = match.group(1)
|
||||
fname = match.group(2)
|
||||
tag = match.group(0)
|
||||
fname = match.group("fname")
|
||||
if re.match("(https?|ftp)://", fname):
|
||||
return tag
|
||||
return tag.replace(
|
||||
|
|
|
@ -535,7 +535,8 @@ order by ordinal""", mid)):
|
|||
def _rewriteMediaRefs(self):
|
||||
col = self.col
|
||||
def rewriteRef(key):
|
||||
all, fname = match
|
||||
all = match.group(0)
|
||||
fname = match.group("fname")
|
||||
if all in state['mflds']:
|
||||
# we've converted this field before
|
||||
new = state['mflds'][all]
|
||||
|
@ -590,9 +591,9 @@ order by ordinal""", mid)):
|
|||
state = dict(mflds={}, fields=0)
|
||||
for t in m['tmpls']:
|
||||
for r in regexps:
|
||||
for match in re.findall(r, t['qfmt']):
|
||||
for match in re.finditer(r, t['qfmt']):
|
||||
rewriteRef('qfmt')
|
||||
for match in re.findall(r, t['afmt']):
|
||||
for match in re.finditer(r, t['afmt']):
|
||||
rewriteRef('afmt')
|
||||
if state['fields']:
|
||||
col.models.save(m)
|
||||
|
|
Loading…
Reference in a new issue