diff MoinMoin/formatter/__init__.py @ 2779:c9dd12befda7

wiki parser: match everything looking like a macro and either execute it (macro imports ok) or render the macro markup as text (macro import fails, error msg is in title). This makes scan_rules independent of wiki, so we can move all re.compile time to Parser class (doing it only once on module import time).
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 28 Aug 2007 13:43:11 +0200
parents 3a6a25169f55
children d2e9afd64276
line wrap: on
line diff
--- a/MoinMoin/formatter/__init__.py	Tue Aug 28 03:12:46 2007 +0200
+++ b/MoinMoin/formatter/__init__.py	Tue Aug 28 13:43:11 2007 +0200
@@ -304,10 +304,19 @@
 
     # Dynamic stuff / Plugins ############################################
 
-    def macro(self, macro_obj, name, args):
+    def macro(self, macro_obj, name, args, markup=None):
         # call the macro
-        return macro_obj.execute(name, args)
-
+        try:
+            return macro_obj.execute(name, args)
+        except ImportError, err:
+            errmsg = unicode(err)
+            if markup:
+                errmsg = wikiutil.escape(errmsg)
+                return (self.span(1, title=errmsg) +
+                        self.text(markup) +
+                        self.span(0))
+            else:
+                return self.text(errmsg)
     def _get_bang_args(self, line):
         if line.startswith('#!'):
             try: