annotate MoinMoin/parser/text_html.py @ 657:016a8a3ef354

wikiutil.MimeType class, renamed parsers to mimetype like module names
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 16 May 2006 20:12:29 +0200
parents MoinMoin/parser/html.py@7f11b74d0506
children bb2e053067fb
rev   line source
650
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
2 """
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
3 MoinMoin - HTML Parser
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
4
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
5 @copyright: 2006 by MoinMoin:AlexanderSchremmer
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
6 @license: GNU GPL, see COPYING for details.
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
7 """
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
8
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
9 from MoinMoin.support.htmlmarkup import Markup
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
10 from HTMLParser import HTMLParseError
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
11
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
12 Dependencies = []
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
13
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
14 class Parser:
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
15 """
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
16 Sends HTML code after filtering it.
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
17 """
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
18
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
19 extensions = ['.htm', '.html']
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
20 Dependencies = Dependencies
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
21
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
22 def __init__(self, raw, request, **kw):
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
23 self.raw = raw
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
24 self.request = request
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
25
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
26 def format(self, formatter):
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
27 """ Send the text. """
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
28 try:
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
29 self.request.write(formatter.rawHTML(Markup(self.raw).sanitize()))
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
30 except HTMLParseError, e:
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
31 self.request.write(formatter.sysmsg(1) +
651
7f11b74d0506 Fixed string quoting in html parser, added CHANGES entry.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 650
diff changeset
32 formatter.text(u'HTML parsing error: %s in "%s"' % (e.msg,
650
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
33 self.raw.splitlines()[e.lineno - 1].strip())) +
18f106611c2e Added (safe-) HTML parser.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
diff changeset
34 formatter.sysmsg(0))