mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 07:22:23 -04:00
utility for percent-escaping images
This commit is contained in:
parent
b426ad4271
commit
80bb59024c
1 changed files with 9 additions and 1 deletions
|
@ -8,11 +8,12 @@ Media support
|
||||||
"""
|
"""
|
||||||
__docformat__ = 'restructuredtext'
|
__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.db import *
|
||||||
from anki.utils import checksum, genID
|
from anki.utils import checksum, genID
|
||||||
from anki.lang import _
|
from anki.lang import _
|
||||||
|
|
||||||
|
# other code depends on this order, so don't reorder
|
||||||
regexps = ("(?i)(\[sound:([^]]+)\])",
|
regexps = ("(?i)(\[sound:([^]]+)\])",
|
||||||
"(?i)(<img[^>]+src=[\"']?([^\"'>]+)[\"']?[^>]*>)")
|
"(?i)(<img[^>]+src=[\"']?([^\"'>]+)[\"']?[^>]*>)")
|
||||||
|
|
||||||
|
@ -133,6 +134,13 @@ def stripMedia(txt):
|
||||||
txt = re.sub(reg, "", txt)
|
txt = re.sub(reg, "", txt)
|
||||||
return 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
|
# Rebuilding DB
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue