From 7074893af741a7fecd1fd57523b77b208d247da7 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 8 Aug 2018 11:38:45 +1000 Subject: [PATCH] rewrite data uris from html pastes as well --- aqt/editor.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index 4e75ba095..a8534bf2f 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -562,8 +562,7 @@ to a cloze type first, via Edit>Change Note Type.""")) return self.fnameToLink(fname) def _addMediaFromData(self, fname, data): - fname = self.mw.col.media.writeData(fname, data) - return self.fnameToLink(fname) + return self.mw.col.media.writeData(fname, data) def onRecSound(self): try: @@ -610,7 +609,7 @@ to a cloze type first, via Edit>Change Note Type.""")) or s.startswith("ftp://") or s.startswith("file://")) - def inlinedImageToLink(self, txt): + def inlinedImageToFilename(self, txt): prefix = "data:image/" suffix = ";base64," for ext in ("jpeg", "png", "gif"): @@ -624,6 +623,13 @@ to a cloze type first, via Edit>Change Note Type.""")) return "" + def inlinedImageToLink(self, src): + fname = self.inlinedImageToFilename(src) + if fname: + return self.fnameToLink(fname) + + return "" + # ext should include dot def _addPastedImage(self, data, ext): # hash and write @@ -709,6 +715,9 @@ to a cloze type first, via Edit>Change Note Type.""")) fname = self._retrieveURL(src) if fname: tag['src'] = fname + elif src.startswith("data:image/"): + # and convert inlined data + tag['src'] = self.inlinedImageToFilename(src) html = str(doc) return html