Comments editor: Strip HTML comments from markup

This commit is contained in:
Kovid Goyal 2010-12-23 11:25:08 -07:00
parent f8d96fb9d4
commit e59d0037f1

View File

@ -62,6 +62,8 @@ class EditorWidget(QWebView): # {{{
def __init__(self, parent=None): def __init__(self, parent=None):
QWebView.__init__(self, parent) QWebView.__init__(self, parent)
self.comments_pat = re.compile(r'<!--.*?-->', re.DOTALL)
for wac, name, icon, text, checkable in [ for wac, name, icon, text, checkable in [
('ToggleBold', 'bold', 'format-text-bold', _('Bold'), True), ('ToggleBold', 'bold', 'format-text-bold', _('Bold'), True),
('ToggleItalic', 'italic', 'format-text-italic', _('Italic'), ('ToggleItalic', 'italic', 'format-text-italic', _('Italic'),
@ -213,6 +215,7 @@ class EditorWidget(QWebView): # {{{
raw = unicode(self.page().mainFrame().toHtml()) raw = unicode(self.page().mainFrame().toHtml())
raw = xml_to_unicode(raw, strip_encoding_pats=True, raw = xml_to_unicode(raw, strip_encoding_pats=True,
resolve_entities=True)[0] resolve_entities=True)[0]
raw = self.comments_pat.sub('', raw)
try: try:
root = html.fromstring(raw) root = html.fromstring(raw)