mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
strip img path when dragging
This commit is contained in:
parent
c40b3ba9a6
commit
cac5f9306f
1 changed files with 10 additions and 10 deletions
|
@ -869,17 +869,10 @@ class EditorWebView(AnkiWebView):
|
||||||
oldmime = evt.mimeData()
|
oldmime = evt.mimeData()
|
||||||
# coming from this program?
|
# coming from this program?
|
||||||
if evt.source():
|
if evt.source():
|
||||||
# if they're copying just an image, we need to turn it into html
|
assert oldmime.hasHtml()
|
||||||
# again
|
|
||||||
txt = ""
|
|
||||||
mime = QMimeData()
|
mime = QMimeData()
|
||||||
if not oldmime.hasHtml() and oldmime.hasUrls():
|
# fix img src links
|
||||||
# qt gives it to us twice
|
mime.setHtml(self._relativeFiles(oldmime.html()))
|
||||||
txt += '<img src="%s">' % os.path.basename(
|
|
||||||
oldmime.urls()[0].toString())
|
|
||||||
mime.setHtml(txt)
|
|
||||||
else:
|
|
||||||
mime.setHtml(oldmime.html())
|
|
||||||
else:
|
else:
|
||||||
mime = self._processMime(oldmime)
|
mime = self._processMime(oldmime)
|
||||||
# create a new event with the new mime data
|
# create a new event with the new mime data
|
||||||
|
@ -1001,3 +994,10 @@ class EditorWebView(AnkiWebView):
|
||||||
file.write(filecontents)
|
file.write(filecontents)
|
||||||
file.close()
|
file.close()
|
||||||
return self.editor._addMedia(path)
|
return self.editor._addMedia(path)
|
||||||
|
|
||||||
|
def _relativeFiles(self, html):
|
||||||
|
# when an image is dragged, the relative img src= links end up as a
|
||||||
|
# full local path. we want to strip that back to a relative path
|
||||||
|
def repl(match):
|
||||||
|
return '<img src="%s">' % os.path.basename(match.group(2))
|
||||||
|
return re.sub(self.editor.mw.col.media.regexps[1], repl, html)
|
||||||
|
|
Loading…
Reference in a new issue