Handle cite attribute

This commit is contained in:
Peter J. Holzer 2019-06-18 22:11:23 +02:00
parent 589a217b1b
commit c9a336e58f
1 changed files with 11 additions and 2 deletions

View File

@ -469,12 +469,15 @@ class HTMLPart(html.parser.HTMLParser):
if href: if href:
self.base = href[0] self.base = href[0]
elif tag in self.allowed_tags: elif tag in self.allowed_tags:
cleaned_attrs, extra = self.clean_attrs(tag, attrs)
attrstr = "".join( attrstr = "".join(
[' %s="%s"' % (a[0], html.escape(a[1])) if a[1] else ' %s' % (a[0]) [' %s="%s"' % (a[0], html.escape(a[1])) if a[1] else ' %s' % (a[0])
for a in self.clean_attrs(tag, attrs) for a in cleaned_attrs
] ]
) )
self.content.append("<%s%s>" % ( tag, attrstr )) self.content.append("<%s%s>" % ( tag, attrstr ))
if extra:
self.content.append(extra)
elif tag in self.hide_tags: elif tag in self.hide_tags:
self.hide = True self.hide = True
elif tag in self.ignore_tags: elif tag in self.ignore_tags:
@ -507,6 +510,7 @@ class HTMLPart(html.parser.HTMLParser):
"noshade", "type", "noshade", "type",
] ]
clean_attrs = [] clean_attrs = []
extra = None
for a in attrs: for a in attrs:
if a[0] in safe_attrs: if a[0] in safe_attrs:
clean_attrs.append(a) clean_attrs.append(a)
@ -527,9 +531,14 @@ class HTMLPart(html.parser.HTMLParser):
print("Ignored src attribute", a, file=sys.stderr) print("Ignored src attribute", a, file=sys.stderr)
elif a[0] == "target": elif a[0] == "target":
pass pass
elif a[0] == "cite":
if a[1].startswith("mid:"):
mid = a[1][4:]
encmid = encode_message_id(mid)
extra = "<a class='citesource' href='../%s'>\u2397</a>" % encmid
else: else:
print("Encountered unknown attribute", a, file=sys.stderr) print("Encountered unknown attribute", a, file=sys.stderr)
return clean_attrs return clean_attrs, extra
class TextEnrichedPart: class TextEnrichedPart: