mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 07:52:24 -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,7 +254,21 @@ def _filterHTML(html):
|
|||
doc = BeautifulSoup(html)
|
||||
# filter out implicit formatting from webkit
|
||||
for tag in doc("span", "Apple-style-span"):
|
||||
tag.replaceWithChildren()
|
||||
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()
|
||||
for tag in doc("font", "Apple-style-span"):
|
||||
# strip all but colour attr from implicit font tags
|
||||
if 'color' in dict(tag.attrs):
|
||||
|
@ -949,8 +963,10 @@ class EditorWebView(AnkiWebView):
|
|||
clip = self.editor.mw.app.clipboard()
|
||||
mime = clip.mimeData(mode=mode)
|
||||
if mime.hasHtml() and mime.html().startswith("<!--anki-->"):
|
||||
# pasting from another field
|
||||
mime.setHtml(mime.html()[11:])
|
||||
# pasting from another field, filter extraneous webkit formatting
|
||||
html = mime.html()[11:]
|
||||
html = _filterHTML(html)
|
||||
mime.setHtml(html)
|
||||
return
|
||||
self.saveClip(mode=mode)
|
||||
if keep:
|
||||
|
|
Loading…
Reference in a new issue