use <base> instead of munging image urls

This commit is contained in:
Damien Elmes 2009-04-25 02:17:00 +09:00
parent 840c3549b4
commit 29bbbe0416
2 changed files with 13 additions and 16 deletions

View file

@ -185,24 +185,8 @@ def restoreHeader(widget, key):
widget.restoreState(ankiqt.mw.config[key])
def mungeQA(deck, txt):
def quote(match):
match = unicode(match.group(1))
if match.lower().startswith("http"):
src = match
else:
if sys.platform.startswith("win32"):
prefix = u"file:///"
else:
prefix = u"file://"
src = prefix + unicode(
urllib.quote(os.path.join(deck.mediaDir(
create=True), match).encode("utf-8")), "utf-8")
return src
def quoteImg(match):
return 'img src="%s"' % quote(match)
txt = renderLatex(deck, txt)
txt = stripSounds(txt)
txt = re.sub('img src="(.*?)"', quoteImg, txt)
return txt
class ProgressWin(object):

View file

@ -106,6 +106,19 @@ class View(object):
self.buffer = self.addStyles() + self.buffer
# hook for user css
runHook("preFlushHook")
if self.main.deck.mediaDir():
if sys.platform.startswith("win32"):
prefix = u"file:///"
else:
prefix = u"file://"
base = prefix + unicode(
urllib.quote(self.main.deck.mediaDir().encode("utf-8")),
"utf-8")
base = '<base href="%s/">' % base
else:
base = ""
self.buffer = '''<html><head>%s</head><body>%s</body></html>''' % (
base, self.buffer)
#print self.buffer.encode("utf-8")
self.body.setHtml(self.buffer)