strip all non-src elements when copying&pasting images between fields

This commit is contained in:
Damien Elmes 2013-05-22 09:09:50 +09:00
parent 81b4e521cc
commit 26f513a7a7

View File

@ -315,8 +315,9 @@ def _filterHTML(html):
else: else:
# remove completely # remove completely
tag.replaceWithChildren() tag.replaceWithChildren()
# turn file:/// links into relative ones # now images
for tag in doc("img"): for tag in doc("img"):
# turn file:/// links into relative ones
try: try:
if tag['src'].lower().startswith("file://"): if tag['src'].lower().startswith("file://"):
tag['src'] = os.path.basename(tag['src']) tag['src'] = os.path.basename(tag['src'])
@ -324,6 +325,10 @@ def _filterHTML(html):
# for some bizarre reason, mnemosyne removes src elements # for some bizarre reason, mnemosyne removes src elements
# from missing media # from missing media
pass pass
# strip all other attributes, including implicit max-width
for attr, val in tag.attrs:
if attr != "src":
del tag[attr]
# strip superfluous elements # strip superfluous elements
for elem in "html", "head", "body", "meta": for elem in "html", "head", "body", "meta":
for tag in doc(elem): for tag in doc(elem):