mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02: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:
|
||||
fname = self.urlToFile(url)
|
||||
if not fname:
|
||||
return None
|
||||
return '<a href="{}">{}</a>'.format(
|
||||
url, html.escape(urllib.parse.unquote(url))
|
||||
)
|
||||
return self.fnameToLink(fname)
|
||||
|
||||
def fnameToLink(self, fname: str) -> str:
|
||||
|
@ -1261,7 +1263,7 @@ class EditorWebView(AnkiWebView):
|
|||
url = qurl.toString()
|
||||
# chrome likes to give us the URL twice with a \n
|
||||
url = url.splitlines()[0]
|
||||
buf += self.editor.urlToLink(url) or ""
|
||||
buf += self.editor.urlToLink(url)
|
||||
|
||||
return buf
|
||||
|
||||
|
@ -1279,16 +1281,9 @@ class EditorWebView(AnkiWebView):
|
|||
if extended and token.startswith("data:image/"):
|
||||
processed.append(self.editor.inlinedImageToLink(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)
|
||||
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:
|
||||
token = html.escape(token).replace("\t", " " * 4)
|
||||
# if there's more than one consecutive space,
|
||||
|
|
Loading…
Reference in a new issue