annotate MoinMoin/formatter/__init__.py @ 1920:b06ef2a53efa

'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 30 Mar 2007 21:50:50 +0200
parents bb2e053067fb
children 01f05e74aa9c
rev   line source
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
2 """
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
3 MoinMoin - Formatter Package and FormatterBase
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
4
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
5 See "base.py" for the formatter interface.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
6
1918
bb2e053067fb fixing copyright headers: remove umlauts (encoding troubles), make epydoc compatible, reformat
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1889
diff changeset
7 @copyright: 2000-2004 by Juergen Hermann <jh@web.de>
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
8 @license: GNU GPL, see COPYING for details.
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
9 """
1181
a7f8dceb4410 remove types module usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 999
diff changeset
10 import re
a7f8dceb4410 remove types module usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 999
diff changeset
11
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
12 from MoinMoin.util import pysupport
1181
a7f8dceb4410 remove types module usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 999
diff changeset
13 from MoinMoin import wikiutil
0
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
14
77665d8e2254 tag of nonpublic@localhost--archive/moin--enterprise--1.5--base-0
Thomas Waldmann <tw-public@gmx.de>
parents:
diff changeset
15 modules = pysupport.getPackageModules(__file__)
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 0
diff changeset
16
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
17
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
18 class FormatterBase:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
19 """ This defines the output interface used all over the rest of the code.
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
20
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
21 Note that no other means should be used to generate _content_ output,
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
22 while navigational elements (HTML page header/footer) and the like
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
23 can be printed directly without violating output abstraction.
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
24 """
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
25
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
26 hardspace = ' '
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
27
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
28 def __init__(self, request, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
29 self.request = request
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
30 self._ = request.getText
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
31
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
32 self._store_pagelinks = kw.get('store_pagelinks', 0)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
33 self._terse = kw.get('terse', 0)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
34 self.pagelinks = []
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
35 self.in_p = 0
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
36 self.in_pre = 0
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
37 self._highlight_re = None
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
38 self._base_depth = 0
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
39
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
40 def set_highlight_re(self, hi_re=None):
1181
a7f8dceb4410 remove types module usage
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 999
diff changeset
41 if isinstance(hi_re, (str, unicode)):
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
42 try:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
43 self._highlight_re = re.compile(hi_re, re.U + re.IGNORECASE)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
44 except re.error:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
45 hi_re = re.escape(hi_re)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
46 self._highlight_re = re.compile(hi_re, re.U + re.IGNORECASE)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
47 else:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
48 self._highlight_re = hi_re
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
49
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
50 def lang(self, on, lang_name):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
51 return ""
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
52
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
53 def setPage(self, page):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
54 self.page = page
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
55
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
56 def sysmsg(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
57 """ Emit a system message (embed it into the page).
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
58
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
59 Normally used to indicate disabled options, or invalid markup.
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
60 """
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
61 return ""
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
62
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
63 # Document Level #####################################################
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 907
diff changeset
64
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
65 def startDocument(self, pagename):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
66 return ""
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
67
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
68 def endDocument(self):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
69 return ""
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
70
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
71 def startContent(self, content_id="content", **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
72 return ""
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
73
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
74 def endContent(self):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
75 return ""
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
76
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
77 # Links ##############################################################
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 907
diff changeset
78
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
79 def pagelink(self, on, pagename='', page=None, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
80 """ make a link to page <pagename>. Instead of supplying a pagename,
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
81 it is also possible to give a live Page object, then page.page_name
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
82 will be used.
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
83 """
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 907
diff changeset
84 if not self._store_pagelinks or not on or kw.get('generated'):
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
85 return ''
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
86 if not pagename and page:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
87 pagename = page.page_name
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
88 pagename = self.request.normalizePagename(pagename)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
89 if pagename and pagename not in self.pagelinks:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
90 self.pagelinks.append(pagename)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
91
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
92 def interwikilink(self, on, interwiki='', pagename='', **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
93 """ calls pagelink() for internal interwikilinks
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
94 to make sure they get counted for self.pagelinks.
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
95 IMPORTANT: on and off must be called with same parameters, see
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
96 also the text_html formatter.
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
97 """
828
902c34d95085 quoting for attachment filenames, wikiutil.load_wikimap, split_wiki can parse quoting, join_wiki does url_quote
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 661
diff changeset
98 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, '%s:"%s"' % (interwiki, pagename))
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
99 if wikitag == 'Self' or wikitag == self.request.cfg.interwikiname:
1183
bc84eae93f8c replace usage of find by 'in' operator
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1181
diff changeset
100 if '#' in wikitail:
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
101 wikitail, kw['anchor'] = wikitail.split('#', 1)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
102 wikitail = wikiutil.url_unquote(wikitail)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
103 return self.pagelink(on, wikitail, **kw)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
104 return ''
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 907
diff changeset
105
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
106 def url(self, on, url=None, css=None, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
107 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
108
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
109 # Attachments ######################################################
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
110
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
111 def attachment_link(self, url, text, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
112 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
113 def attachment_image(self, url, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
114 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
115 def attachment_drawing(self, url, text, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
116 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
117
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
118 def attachment_inlined(self, url, text, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
119 from MoinMoin.action import AttachFile
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
120 import os
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
121 _ = self.request.getText
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
122 pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
123 fname = wikiutil.taintfilename(filename)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
124 fpath = AttachFile.getFilename(self.request, pagename, fname)
1805
ebcebba1afb3 removed some unused attributes, used 'dummy' for dummies
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1520
diff changeset
125 ext = os.path.splitext(filename)[1]
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
126 Parser = wikiutil.getParserForExtension(self.request.cfg, ext)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
127 if Parser is not None:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
128 try:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
129 content = file(fpath, 'r').read()
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
130 # Try to decode text. It might return junk, but we don't
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
131 # have enough information with attachments.
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
132 content = wikiutil.decodeUnknownInput(content)
1889
1405a38ae848 give the attachment filename to a colorizing parser
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1868
diff changeset
133 colorizer = Parser(content, self.request, filename=filename)
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
134 colorizer.format(self)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
135 except IOError:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
136 pass
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
137
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
138 return self.attachment_link(url, text)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
139
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
140 def anchordef(self, name):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
141 return ""
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
142
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
143 def line_anchordef(self, lineno):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
144 return ""
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
145
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
146 def anchorlink(self, on, name='', **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
147 return ""
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
148
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
149 def line_anchorlink(self, on, lineno=0):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
150 return ""
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
151
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
152 def image(self, src=None, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
153 """An inline image.
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
154
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
155 Extra keyword arguments are according to the HTML <img> tag attributes.
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
156 In particular an 'alt' or 'title' argument should give a description
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
157 of the image.
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
158 """
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
159 title = src
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
160 for titleattr in ('title', 'html__title', 'alt', 'html__alt'):
1868
64507f46beb2 reduce usage of has_key()
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1805
diff changeset
161 if titleattr in kw:
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
162 title = kw[titleattr]
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
163 break
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
164 if title:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
165 return '[Image:%s]' % title
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
166 return '[Image]'
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
167
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
168 def smiley(self, text):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
169 return text
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
170
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
171 def nowikiword(self, text):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
172 return self.text(text)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
173
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
174 # Text and Text Attributes ###########################################
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 907
diff changeset
175
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
176 def text(self, text, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
177 if not self._highlight_re:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
178 return self._text(text)
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 907
diff changeset
179
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
180 result = []
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
181 lastpos = 0
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
182 match = self._highlight_re.search(text)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
183 while match and lastpos < len(text):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
184 # add the match we found
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
185 result.append(self._text(text[lastpos:match.start()]))
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
186 result.append(self.highlight(1))
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
187 result.append(self._text(match.group(0)))
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
188 result.append(self.highlight(0))
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
189
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
190 # search for the next one
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
191 lastpos = match.end() + (match.end() == lastpos)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
192 match = self._highlight_re.search(text, lastpos)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
193
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
194 result.append(self._text(text[lastpos:]))
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
195 return ''.join(result)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
196
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
197 def _text(self, text):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
198 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
199
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
200 def strong(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
201 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
202
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
203 def emphasis(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
204 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
205
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
206 def underline(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
207 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
208
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
209 def highlight(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
210 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
211
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
212 def sup(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
213 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
214
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
215 def sub(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
216 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
217
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
218 def strike(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
219 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
220
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
221 def code(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
222 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
223
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
224 def preformatted(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
225 self.in_pre = on != 0
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
226
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
227 def small(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
228 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
229
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
230 def big(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
231 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
232
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
233 # special markup for syntax highlighting #############################
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
234
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
235 def code_area(self, on, code_id, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
236 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
237
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
238 def code_line(self, on):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
239 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
240
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
241 def code_token(self, tok_text, tok_type):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
242 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
243
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
244 # Paragraphs, Lines, Rules ###########################################
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
245
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
246 def linebreak(self, preformatted=1):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
247 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
248
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
249 def paragraph(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
250 self.in_p = on != 0
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
251
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
252 def rule(self, size=0, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
253 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
254
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
255 def icon(self, type):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
256 return type
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
257
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
258 # Lists ##############################################################
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
259
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
260 def number_list(self, on, type=None, start=None, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
261 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
262
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
263 def bullet_list(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
264 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
265
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
266 def listitem(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
267 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
268
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
269 def definition_list(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
270 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
271
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
272 def definition_term(self, on, compact=0, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
273 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
274
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
275 def definition_desc(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
276 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
277
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
278 def heading(self, on, depth, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
279 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
280
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
281 # Tables #############################################################
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 907
diff changeset
282
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
283 def table(self, on, attrs={}, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
284 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
285
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
286 def table_row(self, on, attrs={}, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
287 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
288
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
289 def table_cell(self, on, attrs={}, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
290 raise NotImplementedError
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
291
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
292 # Dynamic stuff / Plugins ############################################
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 907
diff changeset
293
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
294 def macro(self, macro_obj, name, args):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
295 # call the macro
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 907
diff changeset
296 return macro_obj.execute(name, args)
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
297
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
298 def _get_bang_args(self, line):
1184
b1deb9496f41 use startswith/endswith
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1183
diff changeset
299 if line.startswith('#!'):
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
300 try:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
301 name, args = line[2:].split(None, 1)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
302 except ValueError:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
303 return ''
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
304 else:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
305 return args
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
306 return None
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
307
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
308 def parser(self, parser_name, lines):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
309 """ parser_name MUST be valid!
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
310 writes out the result instead of returning it!
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
311 """
1520
563bfe02b04f Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1184
diff changeset
312 parser = wikiutil.searchAndImportPlugin(self.request.cfg, "parser", parser_name)
563bfe02b04f Removed a lot of ugly MimeType() calls, refactored it into a helper, fixed page rendering for missing parsers.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1184
diff changeset
313
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
314 args = self._get_bang_args(lines[0])
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
315 if args is not None:
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
316 lines = lines[1:]
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
317 p = parser('\n'.join(lines), self.request, format_args=args)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
318 p.format(self)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
319 del p
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
320 return ''
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
321
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
322 # Other ##############################################################
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 907
diff changeset
323
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
324 def div(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
325 """ open/close a blocklevel division """
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
326 return ""
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 907
diff changeset
327
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
328 def span(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
329 """ open/close a inline span """
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
330 return ""
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 907
diff changeset
331
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
332 def rawHTML(self, markup):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
333 """ This allows emitting pre-formatted HTML markup, and should be
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
334 used wisely (i.e. very seldom).
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
335
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
336 Using this event while generating content results in unwanted
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
337 effects, like loss of markup or insertion of CDATA sections
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
338 when output goes to XML formats.
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
339 """
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
340
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
341 import formatter, htmllib
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
342 from MoinMoin.util import simpleIO
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
343
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
344 # Regenerate plain text
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
345 f = simpleIO()
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
346 h = htmllib.HTMLParser(formatter.AbstractFormatter(formatter.DumbWriter(f)))
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
347 h.feed(markup)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
348 h.close()
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
349
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
350 return self.text(f.getvalue())
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
351
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
352 def escapedText(self, on, **kw):
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
353 """ This allows emitting text as-is, anything special will
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
354 be escaped (at least in HTML, some text output format
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
355 would possibly do nothing here)
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
356 """
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
357 return ""
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
358
1920
b06ef2a53efa 'make pylint', fixed lots of minor stuff found by pylint (and there is still lots left to do)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1918
diff changeset
359 def comment(self, text, **kw):
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
360 return ""
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 407
diff changeset
361