mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 00:12:25 -04:00
filter html when pasting/dragging between fields
This commit is contained in:
parent
63990af4b2
commit
e40c4483a9
1 changed files with 19 additions and 3 deletions
|
@ -254,6 +254,20 @@ def _filterHTML(html):
|
||||||
doc = BeautifulSoup(html)
|
doc = BeautifulSoup(html)
|
||||||
# filter out implicit formatting from webkit
|
# filter out implicit formatting from webkit
|
||||||
for tag in doc("span", "Apple-style-span"):
|
for tag in doc("span", "Apple-style-span"):
|
||||||
|
preserve = ""
|
||||||
|
for item in tag['style'].split(";"):
|
||||||
|
try:
|
||||||
|
k, v = item.split(":")
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
if k.strip() == "color":
|
||||||
|
preserve += "color:%s;" % v
|
||||||
|
if preserve:
|
||||||
|
# preserve colour attribute, delete implicit class
|
||||||
|
tag.attrs = ((u"style", preserve),)
|
||||||
|
del tag['class']
|
||||||
|
else:
|
||||||
|
# strip completely
|
||||||
tag.replaceWithChildren()
|
tag.replaceWithChildren()
|
||||||
for tag in doc("font", "Apple-style-span"):
|
for tag in doc("font", "Apple-style-span"):
|
||||||
# strip all but colour attr from implicit font tags
|
# strip all but colour attr from implicit font tags
|
||||||
|
@ -949,8 +963,10 @@ class EditorWebView(AnkiWebView):
|
||||||
clip = self.editor.mw.app.clipboard()
|
clip = self.editor.mw.app.clipboard()
|
||||||
mime = clip.mimeData(mode=mode)
|
mime = clip.mimeData(mode=mode)
|
||||||
if mime.hasHtml() and mime.html().startswith("<!--anki-->"):
|
if mime.hasHtml() and mime.html().startswith("<!--anki-->"):
|
||||||
# pasting from another field
|
# pasting from another field, filter extraneous webkit formatting
|
||||||
mime.setHtml(mime.html()[11:])
|
html = mime.html()[11:]
|
||||||
|
html = _filterHTML(html)
|
||||||
|
mime.setHtml(html)
|
||||||
return
|
return
|
||||||
self.saveClip(mode=mode)
|
self.saveClip(mode=mode)
|
||||||
if keep:
|
if keep:
|
||||||
|
|
Loading…
Reference in a new issue