mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
rewrite data uris from html pastes as well
This commit is contained in:
parent
0acf9b38a4
commit
7074893af7
1 changed files with 12 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue