This commit is contained in:
parent
61e8611b7b
commit
eaf935c3ff
@ -1091,34 +1091,35 @@ class EditorWebView(AnkiWebView):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
txt = mime.text()
|
txt = mime.text()
|
||||||
|
processed = ''
|
||||||
|
lines = txt.split("\n")
|
||||||
|
|
||||||
# inlined data in base64?
|
for line in lines:
|
||||||
if txt.startswith("data:image/"):
|
for token in re.split('(\S+)', line):
|
||||||
return self.editor.inlinedImageToLink(txt)
|
# inlined data in base64?
|
||||||
|
if token.startswith("data:image/"):
|
||||||
|
processed += self.editor.inlinedImageToLink(token)
|
||||||
|
elif self.editor.isURL(token):
|
||||||
|
# if the user is pasting an image or sound link, convert it to local
|
||||||
|
link = self.editor.urlToLink(token)
|
||||||
|
if link:
|
||||||
|
processed += link
|
||||||
|
else:
|
||||||
|
# not media; add it as a normal link
|
||||||
|
link = '<a href="{}">{}</a>'.format(token, html.escape(token))
|
||||||
|
processed += link
|
||||||
|
else:
|
||||||
|
token = html.escape(token).replace("\t", " " * 4)
|
||||||
|
# if there's more than one consecutive space,
|
||||||
|
# use non-breaking spaces for the second one on
|
||||||
|
def repl(match):
|
||||||
|
return match.group(1).replace(" ", " ") + " "
|
||||||
|
token = re.sub(" ( +)", repl, token)
|
||||||
|
processed += token
|
||||||
|
|
||||||
# if the user is pasting an image or sound link, convert it to local
|
processed += "<br>"
|
||||||
if self.editor.isURL(txt):
|
# return without last <br>
|
||||||
url = txt.split("\r\n")[0]
|
return processed[:-4]
|
||||||
link = self.editor.urlToLink(url)
|
|
||||||
if link:
|
|
||||||
return link
|
|
||||||
|
|
||||||
# not media; add it as a normal link if pasting with shift
|
|
||||||
link = '<a href="{}">{}</a>'.format(url, html.escape(txt))
|
|
||||||
return link
|
|
||||||
|
|
||||||
# normal text; convert it to HTML
|
|
||||||
txt = html.escape(txt)
|
|
||||||
txt = txt.replace("\n", "<br>").replace("\t", " " * 4)
|
|
||||||
|
|
||||||
# if there's more than one consecutive space,
|
|
||||||
# use non-breaking spaces for the second one on
|
|
||||||
def repl(match):
|
|
||||||
return match.group(1).replace(" ", " ") + " "
|
|
||||||
|
|
||||||
txt = re.sub(" ( +)", repl, txt)
|
|
||||||
|
|
||||||
return txt
|
|
||||||
|
|
||||||
def _processHtml(self, mime: QMimeData) -> Tuple[Optional[str], bool]:
|
def _processHtml(self, mime: QMimeData) -> Tuple[Optional[str], bool]:
|
||||||
if not mime.hasHtml():
|
if not mime.hasHtml():
|
||||||
|
Loading…
Reference in New Issue
Block a user