changeset 3185:5e0aede39dea

- The DocBook formatter will try to execute any macros it encounters and will emit a comment if the macro doesn't work with the formatter. - Added blacklisting for macros that doen't work with the DocBook formatter and which should not be executed - Added the ShowSmileys to the blacklist as the output of it causes the xml parser to choke. - Added the TOC macro to the blacklist as DocBooks create their own TOC on the fly.
author Mikko Virkkilä <>
date Wed, 05 Mar 2008 00:30:33 +0100
parents 4c7c12b775e0
children a36faa9f9d9f
files MoinMoin/formatter/
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/formatter/	Wed Mar 05 00:10:19 2008 +0100
+++ b/MoinMoin/formatter/	Wed Mar 05 00:30:33 2008 +0100
@@ -31,6 +31,8 @@
     #this list is extended as the page is parsed. Could be optimized by adding them here?
     section_should_break = ['abstract', 'para', 'emphasis']
+    blacklisted_macros = ('TableOfContents', 'ShowSmileys')
     def __init__(self, request, doctype="article", **kw):
         FormatterBase.__init__(self, request, **kw)
@@ -526,13 +528,21 @@
             return ""
     def macro(self, macro_obj, name, args, markup=None):
-        if name == "Include":
+        if name in self.blacklisted_macros:
+            self._emitComment("The macro %s doesn't work with the DocBook formatter." % name)
+        elif name == "Include":
             text = FormatterBase.macro(self, macro_obj, name, args)
             if text.strip():
                 self._copyExternalNodes(Sax.FromXml(text).documentElement.childNodes, exclude=("title",))
-            self._emitComment("%s-macro is not supported by the docbook formatter"%name)
+            text = FormatterBase.macro(self, macro_obj, name, args)
+            if text:
+                from xml.parsers.expat import ExpatError
+                try:
+                    self._copyExternalNodes(Sax.FromXml(text).documentElement.childNodes, exclude=excludes)
+                except ExpatError:
+                    self._emitComment("The macro %s caused an error and should be blacklisted. It returned the data '%s' which caused the docbook-formatter to choke. Please file a bug." % (name, text))
         return u""
     def _copyExternalNodes(self, nodes, deep=1, target=None, exclude=()):