From 34b7eaf4c9c9c7f6821b33e7c324857025999189 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 23 May 2013 12:00:28 +0900 Subject: [PATCH] replace implicit styling at the top, and catch style missing case --- aqt/editor.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/aqt/editor.py b/aqt/editor.py index 47f7078ae..fcefddec7 100644 --- a/aqt/editor.py +++ b/aqt/editor.py @@ -287,6 +287,19 @@ document.onclick = function (evt) { def _filterHTML(html): doc = BeautifulSoup(html) + # remove implicit regular font style from outermost element + if doc.span: + try: + attrs = doc.span['style'].split(";") + except (KeyError, TypeError): + attrs = [] + if attrs: + new = [] + for attr in attrs: + sattr = attr.strip() + if sattr and sattr not in ("font-style: normal", "font-weight: normal"): + new.append(sattr) + doc.span['style'] = ";".join(new) # filter out implicit formatting from webkit for tag in doc("span", "Apple-style-span"): preserve = "" @@ -335,15 +348,6 @@ def _filterHTML(html): for elem in "html", "head", "body", "meta": for tag in doc(elem): tag.replaceWithChildren() - # remove outer styling if implicit - if doc.span: - hadExtraAttr = False - for attr in doc.span['style'].split(";"): - attr = attr.strip() - if attr and attr not in ("font-style: normal", "font-weight: normal"): - hadExtraAttr = True - if hadExtraAttr: - doc.span.replaceWithChildren() html = unicode(doc) return html