changeset 1749:3567062fc66f

wikiutil:getProcessingInstructions and getParser added, described in CHANGES
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sun, 21 Jan 2007 19:43:34 +0100
parents dc0db3897437
children 88fa1ffd2574 6f8360e1a4bb
files MoinMoin/wikiutil.py docs/CHANGES
diffstat 2 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/wikiutil.py	Sat Jan 20 22:29:31 2007 +0100
+++ b/MoinMoin/wikiutil.py	Sun Jan 21 19:43:34 2007 +0100
@@ -1645,7 +1645,7 @@
     return ticket == ourticket
 
 def executeText(request, Parser, text, line_anchors=False):
-    '''render text with Parser execute each page element'''
+    """executes raw wiki markup with all page elements"""
     import StringIO
     out = StringIO.StringIO()
     request.redirect(out)
@@ -1656,3 +1656,32 @@
     del out
     return result
 
+def getProcessingInstructions(text):
+    """creates dict of processing instructions from raw wiki markup"""
+    lines = text.split('\n')
+    kw = {}
+    kw["processing_instructions"] = False
+    for line in lines:
+        if line.startswith('#'):
+            for pi in ("format", "refresh", "redirect", "deprecated", "pragma", "form", "acl", "language"):
+                if line[1:].lower().startswith(pi):
+                    kw[str(pi)] = ((line.split(pi))[1]).strip()
+                    kw["processing_instructions"] = True
+                    break
+    return kw
+
+def getParser(request, text):
+    """gets the parser from raw wiki murkup"""
+    pi = getProcessingInstructions(text)
+    pi_format = request.cfg.default_markup or "wiki"
+
+    # check for XML content
+    if text and text[:5] == '<?xml':
+        pi_format = "xslt"
+
+    # check processing instructions
+    if pi.has_key('format'):
+        pi_format = (pi["format"]).lower()
+
+    Parser = searchAndImportPlugin(request.cfg, "parser", pi_format)
+    return Parser
--- a/docs/CHANGES	Sat Jan 20 22:29:31 2007 +0100
+++ b/docs/CHANGES	Sun Jan 21 19:43:34 2007 +0100
@@ -166,6 +166,9 @@
     * There is a new MoinMoin.Page.ItemCache class now with automatic cache
       invalidation based on global edit-log. We currently use it to cache page
       acls, speedup Page.get_rev and reading the page local edit-log.
+    * Added wikiutil.executeText executes raw wiki markup with all page elements
+    * Added wikiutil.getProcessingInstructions creates dict of processing instructions from raw wiki markup
+    * Added wikiutil.getParser gets the parser from raw wiki murkup
 
   New Features:
     * The action menu now calls the actions for the revision of the page you