20
22
while navigational elements (HTML page header/footer) and the like
21
23
can be printed directly without violating output abstraction.
27
# those tags will be automatically reopened if they were auto-closed due to
28
# an enclosing tag being closed:
26
29
format_tags = ['b', 'em', 'highlight', 'sup', 'sub', 'strike', 'code', 'u']
28
unbreakables = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6',
29
'p', 'ol', 'ul', 'li', 'pre', 'a',
31
# those tags want a <p> around them:
32
32
need_p = [] # format_tags[:]
33
33
need_p.extend(['ol', 'a', 'pagelink', 'interwiki', 'macro']) # XXX add more
35
# those tags inhibit auto-generation of a <p> after them:
35
36
no_p_after = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'ol', 'ul', 'pre',
36
37
'small', 'big', 'table', 'td', 'tr', 'dt',
37
38
'codearea', 'codeline', 'codetoken',
41
# if key tag is opened, auto-close all tags in value list if they are open
47
49
for i in xrange(2, 7):
48
50
close_on_open['h%i' % i] = close_on_open['h1']
50
close_on_open = {} # XXX
52
# if key tag is closed, auto-close all tags in value list if they are open
53
54
'table': ['td', 'tr'],
55
'td': ['tr'], # XXX WTF?
59
close_on_close = {} # XXX
61
# FIXME - this overrides the values defined above - FIXME XXX
61
65
def __init__(self, request, **kw):
62
self.request = request
63
self._ = request.getText
66
FormatterBase.__init__(self, request, **kw)
65
self._store_pagelinks = kw.get('store_pagelinks', 0)
66
self._highlight_re = None
70
68
self.document = minidom.Document()
71
69
self.document.documentElement = self.document.createElement('xml')
72
70
self.position = self.document.documentElement
81
79
@param tag: tag name, string
82
80
@param attrs: attributes keywords, ascii or unicode
83
FormatterBase.paragraph(self, 1)
84
84
self.tag_stack.append((tag, attrs))
85
85
node = self.document.createElement(tag)
86
86
for name, value in attrs.items():
95
95
must be the last opened tag!!!
98
FormatterBase.paragraph(self, 0)
99
99
if self.tag_stack[-1][0] != tag:
100
raise ValueError, "<%s> expected <%s> given" % (self.tag_stack[-1][0], tag)
100
raise ValueError, "closing of <%s> expected, but <%s> closed" % (self.tag_stack[-1][0], tag)
101
101
self.position = self.position.parentNode
102
102
return self.tag_stack.pop()
124
124
close_on_open = self.close_on_open.get(tag, [])
125
125
tags_to_reopen = []
127
127
last_tag = self.tag_stack[-1][0]
128
128
if last_tag in close_on_open:
129
129
self._close_tag(last_tag)
154
154
elif last_tag in self.format_tags:
155
155
tags_to_reopen.append(self._close_tag(last_tag))
157
self.request.write("tag_stack: %r\n" % self.tag_stack)
158
158
self.request.write(self.document.documentElement.toprettyxml(" "))
159
raise ValueError, "<%s> expected <%s> given" % (last_tag, tag)
159
raise ValueError, "closing of <%s> expected, but <%s> closed" % (last_tag, tag)
160
160
self._close_tag(tag)
161
161
tags_to_reopen.reverse()
162
162
for tag_name, args in tags_to_reopen:
175
174
self._open_tag('p', type=str(opening_tag))
177
176
def sysmsg(self, on, **kw):
178
177
""" Emit a system message (embed it into the page).
180
Normally used to indicate disabled options, or invalid
179
Normally used to indicate disabled options, or invalid markup.
183
181
return self._set_tag('sysmesg', on, **kw)
220
218
self.text('\n'.join(lines)) +
221
219
self._set_tag('processor', False))
223
def dynamic_content(self, parser, callback, arg_list=[], arg_dict={},
221
def dynamic_content(self, parser, callback, arg_list=[], arg_dict={}, returns_content=1):
225
222
content = parser[callback](*arg_list, **arg_dict)
226
223
if returns_content:
234
231
kw['class'] = str(css)
235
232
return self._set_tag('a', on, **kw)
237
def attachment_link(self, on, url='', **kw):
234
def attachment_link(self, url, text, **kw):
239
return self._set_tag('attachment', on, **kw)
237
return self._set_tag('attachment', 1, **kw) + self.text(text) + self._set_tag('attachment', 0, **kw)
241
239
def attachment_image(self, url, **kw):
330
328
def anchorlink(self, on, name, **kw):
331
329
return self.url(on, "#" + name, **kw)
331
def line_anchordef(self, lineno):
333
return self.anchordef("line-%d" % lineno)
333
337
def underline(self, on, **kw):
334
338
return self._set_tag('u', on)