ensure we match on identical closing quote (#769)

This commit is contained in:
Damien Elmes 2013-05-17 12:23:56 +09:00
parent c45525179b
commit 8f36841281
2 changed files with 11 additions and 8 deletions

View file

@ -13,8 +13,9 @@ from anki.latex import mungeQA
class MediaManager(object): class MediaManager(object):
# other code depends on this order, so don't reorder # other code depends on this order, so don't reorder
regexps = ("(?i)(\[sound:([^]]+)\])", regexps = ("(?i)(\[sound:(?P<fname>[^]]+)\])",
"(?i)(<img[^>]+src=[\"']?([^\"'>]+)[\"']?[^>]*>)") "(?i)(<img[^>]+src=(?P<str>[\"']?)"+
"(?P<fname>[^>]+?)(?P=str)[^>]*>)")
def __init__(self, col, server): def __init__(self, col, server):
self.col = col self.col = col
@ -124,7 +125,8 @@ If the same name exists, compare checksums."""
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:
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()) isLocal = not re.match("(https?|ftp)://", fname.lower())
if isLocal or includeRemote: if isLocal or includeRemote:
l.append(fname) l.append(fname)
@ -167,8 +169,8 @@ If the same name exists, compare checksums."""
if isWin: if isWin:
return string return string
def repl(match): def repl(match):
tag = match.group(1) tag = match.group(0)
fname = match.group(2) fname = match.group("fname")
if re.match("(https?|ftp)://", fname): if re.match("(https?|ftp)://", fname):
return tag return tag
return tag.replace( return tag.replace(

View file

@ -535,7 +535,8 @@ order by ordinal""", mid)):
def _rewriteMediaRefs(self): def _rewriteMediaRefs(self):
col = self.col col = self.col
def rewriteRef(key): def rewriteRef(key):
all, fname = match all = match.group(0)
fname = match.group("fname")
if all in state['mflds']: if all in state['mflds']:
# we've converted this field before # we've converted this field before
new = state['mflds'][all] new = state['mflds'][all]
@ -590,9 +591,9 @@ order by ordinal""", mid)):
state = dict(mflds={}, fields=0) state = dict(mflds={}, fields=0)
for t in m['tmpls']: for t in m['tmpls']:
for r in regexps: for r in regexps:
for match in re.findall(r, t['qfmt']): for match in re.finditer(r, t['qfmt']):
rewriteRef('qfmt') rewriteRef('qfmt')
for match in re.findall(r, t['afmt']): for match in re.finditer(r, t['afmt']):
rewriteRef('afmt') rewriteRef('afmt')
if state['fields']: if state['fields']:
col.models.save(m) col.models.save(m)