url encode images in editor to fix foreign chars in images on linux

This commit is contained in:
Damien Elmes 2012-04-15 14:26:53 +09:00
parent 07a1a49c8d
commit 8355a553fa

View file

@ -3,7 +3,7 @@
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
from aqt.qt import * from aqt.qt import *
import re, os, sys, urllib2, ctypes, simplejson, traceback import re, os, sys, urllib2, ctypes, simplejson, traceback, urllib2
from anki.utils import stripHTML, isWin, isMac, namedtmp from anki.utils import stripHTML, isWin, isMac, namedtmp
from anki.sound import play from anki.sound import play
from anki.hooks import runHook, runFilter from anki.hooks import runHook, runFilter
@ -426,6 +426,8 @@ class Editor(object):
txt = self.mungeHTML(txt) txt = self.mungeHTML(txt)
# misbehaving apps may include a null byte in the text # misbehaving apps may include a null byte in the text
txt = txt.replace("\x00", "") txt = txt.replace("\x00", "")
# reverse the url quoting we added to get images to display
txt = unicode(urllib2.unquote(txt.encode("utf")), "utf8")
self.note.fields[self.currentField] = txt self.note.fields[self.currentField] = txt
self.mw.requireReset() self.mw.requireReset()
if not self.addMode: if not self.addMode:
@ -503,8 +505,11 @@ class Editor(object):
if not self._loaded: if not self._loaded:
# will be loaded when page is ready # will be loaded when page is ready
return return
data = []
for fld, val in self.note.items():
data.append((fld, self.mw.col.media.escapeImages(val)))
self.web.eval("setFields(%s, %d);" % ( self.web.eval("setFields(%s, %d);" % (
simplejson.dumps(self.note.items()), field)) simplejson.dumps(data), field))
self.web.eval("setFonts(%s);" % ( self.web.eval("setFonts(%s);" % (
simplejson.dumps(self.fonts()))) simplejson.dumps(self.fonts())))
self.checkValid() self.checkValid()