mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Fix pasting of local links to unsupported types that contain spaces (#1813)
This change causes local links to unsupported formats like PDF to be handled by _processUrls() instead of _processText, converting them to correct hyperlinks in case they contain spaces.
This commit is contained in:
parent
6f764aeda4
commit
6ea75df292
1 changed files with 6 additions and 11 deletions
|
@ -758,7 +758,9 @@ require("anki/ui").loaded.then(() => require("anki/NoteEditor").instances[0].too
|
||||||
def urlToLink(self, url: str) -> str | None:
|
def urlToLink(self, url: str) -> str | None:
|
||||||
fname = self.urlToFile(url)
|
fname = self.urlToFile(url)
|
||||||
if not fname:
|
if not fname:
|
||||||
return None
|
return '<a href="{}">{}</a>'.format(
|
||||||
|
url, html.escape(urllib.parse.unquote(url))
|
||||||
|
)
|
||||||
return self.fnameToLink(fname)
|
return self.fnameToLink(fname)
|
||||||
|
|
||||||
def fnameToLink(self, fname: str) -> str:
|
def fnameToLink(self, fname: str) -> str:
|
||||||
|
@ -1261,7 +1263,7 @@ class EditorWebView(AnkiWebView):
|
||||||
url = qurl.toString()
|
url = qurl.toString()
|
||||||
# chrome likes to give us the URL twice with a \n
|
# chrome likes to give us the URL twice with a \n
|
||||||
url = url.splitlines()[0]
|
url = url.splitlines()[0]
|
||||||
buf += self.editor.urlToLink(url) or ""
|
buf += self.editor.urlToLink(url)
|
||||||
|
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
|
@ -1279,15 +1281,8 @@ class EditorWebView(AnkiWebView):
|
||||||
if extended and token.startswith("data:image/"):
|
if extended and token.startswith("data:image/"):
|
||||||
processed.append(self.editor.inlinedImageToLink(token))
|
processed.append(self.editor.inlinedImageToLink(token))
|
||||||
elif extended and self.editor.isURL(token):
|
elif extended and self.editor.isURL(token):
|
||||||
# if the user is pasting an image or sound link, convert it to local
|
# if the user is pasting an image or sound link, convert it to local, otherwise paste as a hyperlink
|
||||||
link = self.editor.urlToLink(token)
|
link = self.editor.urlToLink(token)
|
||||||
if link:
|
|
||||||
processed.append(link)
|
|
||||||
else:
|
|
||||||
# not media; add it as a normal link
|
|
||||||
link = '<a href="{}">{}</a>'.format(
|
|
||||||
token, html.escape(urllib.parse.unquote(token))
|
|
||||||
)
|
|
||||||
processed.append(link)
|
processed.append(link)
|
||||||
else:
|
else:
|
||||||
token = html.escape(token).replace("\t", " " * 4)
|
token = html.escape(token).replace("\t", " " * 4)
|
||||||
|
|
Loading…
Reference in a new issue