comparison MoinMoin/formatter/text_docbook.py @ 3195:d186dc68f95f

Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
author Mikko Virkkil? <mvirkkil@cc.hut.fi>
date Wed, 05 Mar 2008 02:36:47 +0100
parents 3e7bfe175714
children 08c2e2727641
comparison
equal deleted inserted replaced
3194:3e7bfe175714 3195:d186dc68f95f
8 8
9 @license: GNU GPL, see COPYING for details. 9 @license: GNU GPL, see COPYING for details.
10 """ 10 """
11 11
12 import os 12 import os
13
13 from xml.dom import getDOMImplementation 14 from xml.dom import getDOMImplementation
14 from xml.dom.ext.reader import Sax 15 from xml.dom.ext.reader import Sax
15 from xml.dom.ext import Node 16 from xml.dom.ext import Node
16 17
17 from MoinMoin.formatter import FormatterBase 18 from MoinMoin.formatter import FormatterBase
18 from MoinMoin import wikiutil 19 from MoinMoin import wikiutil
19 from MoinMoin.error import CompositeError 20 from MoinMoin.error import CompositeError
20 from MoinMoin.action import AttachFile 21 from MoinMoin.action import AttachFile
22
21 23
22 class InternalError(CompositeError): pass 24 class InternalError(CompositeError): pass
23 25
24 try: 26 try:
25 dom = getDOMImplementation("4DOM") 27 dom = getDOMImplementation("4DOM")
158 return "" 160 return ""
159 161
160 def paragraph(self, on, **kw): 162 def paragraph(self, on, **kw):
161 FormatterBase.paragraph(self, on) 163 FormatterBase.paragraph(self, on)
162 164
165 # Let's prevent empty paras
166 if not on:
167 if not self._hasContent(self.cur):
168 oldnode = self.cur
169 self.cur = oldnode.parentNode
170 self.cur.removeChild(oldnode)
171 return ""
172
163 # Let's prevent para inside para 173 # Let's prevent para inside para
164 if on and self.cur.nodeName == "para": 174 if on and self.cur.nodeName == "para":
165 return "" 175 return ""
166 return self._handleNode("para", on) 176 return self._handleNode("para", on)
167 177
205 # but seems to be correct 215 # but seems to be correct
206 return self._handleFormatting("emphasis", on, 216 return self._handleFormatting("emphasis", on,
207 (('role', 'strikethrough'), )) 217 (('role', 'strikethrough'), ))
208 218
209 def code(self, on, **kw): 219 def code(self, on, **kw):
220 # Let's prevent empty code
221 if not on:
222 if not self._hasContent(self.cur):
223 oldnode = self.cur
224 self.cur = oldnode.parentNode
225 self.cur.removeChild(oldnode)
226 return ""
210 return self._handleFormatting("code", on) 227 return self._handleFormatting("code", on)
211 228
212 def preformatted(self, on, **kw): 229 def preformatted(self, on, **kw):
213 return self._handleFormatting("screen", on) 230 return self._handleFormatting("screen", on)
214 231
408 self.cur.appendChild(media) 425 self.cur.appendChild(media)
409 return "" 426 return ""
410 427
411 def transclusion(self, on, **kw): 428 def transclusion(self, on, **kw):
412 # TODO, see text_html formatter 429 # TODO, see text_html formatter
430 self._emitComment('transclusion is not implemented in DocBook formatter')
413 return "" 431 return ""
414 432
415 def transclusion_param(self, **kw): 433 def transclusion_param(self, **kw):
416 # TODO, see text_html formatter 434 # TODO, see text_html formatter
435 self._emitComment('transclusion parameters are not implemented in DocBook formatter')
417 return "" 436 return ""
418 437
419 def smiley(self, text): 438 def smiley(self, text):
420 return self.request.theme.make_icon(text) 439 return self.request.theme.make_icon(text)
421 440
617 636
618 637
619 ### Not supported ################################################### 638 ### Not supported ###################################################
620 639
621 def rule(self, size=0, **kw): 640 def rule(self, size=0, **kw):
641 self._emitComment('rule (<hr>) is not applicable to DocBook')
622 return "" 642 return ""
623 643
624 def small(self, on, **kw): 644 def small(self, on, **kw):
645 if on:
646 self._emitComment('"~-smaller-~" is not applicable to DocBook')
625 return "" 647 return ""
626 648
627 def big(self, on, **kw): 649 def big(self, on, **kw):
650 if on:
651 self._emitComment('"~+bigger+~" is not applicable to DocBook')
628 return "" 652 return ""
629 653
630 ### Tables ########################################################## 654 ### Tables ##########################################################
631 655
632 def table(self, on, attrs=(), **kw): 656 def table(self, on, attrs=(), **kw):