diff --git a/anki/media.py b/anki/media.py index 4cab24780..09c478309 100644 --- a/anki/media.py +++ b/anki/media.py @@ -8,11 +8,12 @@ Media support """ __docformat__ = 'restructuredtext' -import os, shutil, re, urllib2, time, tempfile, unicodedata +import os, shutil, re, urllib2, time, tempfile, unicodedata, urllib from anki.db import * from anki.utils import checksum, genID from anki.lang import _ +# other code depends on this order, so don't reorder regexps = ("(?i)(\[sound:([^]]+)\])", "(?i)(]+src=[\"']?([^\"'>]+)[\"']?[^>]*>)") @@ -133,6 +134,13 @@ def stripMedia(txt): txt = re.sub(reg, "", txt) return txt +def escapeImages(string): + def repl(match): + return match.group(1).replace( + match.group(2), + urllib.quote(match.group(2).encode("utf-8"))) + return re.sub(regexps[1], repl, string) + # Rebuilding DB ##########################################################################