diff MoinMoin/parser/html.py @ 650:18f106611c2e

Added (safe-) HTML parser.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Mon, 15 May 2006 22:31:02 +0200
parents
children 7f11b74d0506
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MoinMoin/parser/html.py	Mon May 15 22:31:02 2006 +0200
@@ -0,0 +1,34 @@
+# -*- coding: iso-8859-1 -*-
+"""
+    MoinMoin - HTML Parser
+
+    @copyright: 2006 by MoinMoin:AlexanderSchremmer
+    @license: GNU GPL, see COPYING for details.
+"""
+
+from MoinMoin.support.htmlmarkup import Markup
+from HTMLParser import HTMLParseError
+
+Dependencies = []
+
+class Parser:
+    """
+        Sends HTML code after filtering it.
+    """
+
+    extensions = ['.htm', '.html']
+    Dependencies = Dependencies
+    
+    def __init__(self, raw, request, **kw):
+        self.raw = raw
+        self.request = request
+
+    def format(self, formatter):
+        """ Send the text. """
+        try:
+            self.request.write(formatter.rawHTML(Markup(self.raw).sanitize()))
+        except HTMLParseError, e:
+            self.request.write(formatter.sysmsg(1) + 
+                formatter.text('HTML parsing error: %s in %r' % (e.msg,
+                                  self.raw.splitlines()[e.lineno - 1].strip())) +
+                formatter.sysmsg(0))