changeset 5442:9dcd78d8be5f

creole parser: respect url_schemas, enable CamelCase links
author Radomir Dopieralski <moindev@sheep.art.pl>
date Sun, 17 Jan 2010 00:10:17 +0100
parents 5bcd98504363
children 8588b6292d9f
files MoinMoin/parser/text_creole.py
diffstat 1 files changed, 17 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/parser/text_creole.py	Sat Jan 16 23:59:26 2010 +0100
+++ b/MoinMoin/parser/text_creole.py	Sun Jan 17 00:10:17 2010 +0100
@@ -25,7 +25,9 @@
 import StringIO
 from MoinMoin import config, wikiutil
 from MoinMoin.macro import Macro
+from MoinMoin import config
 from _creole import Parser as CreoleParser
+from _creole import Rules as CreoleRules
 
 Dependencies = []
 
@@ -59,15 +61,18 @@
         self.request = request
         self.form = request.form
         self.raw = raw
+        self.rules = MoinRules(wiki_words=True,
+                               url_protocols=config.url_schemas)
 
     def format(self, formatter):
         """Create and call the true parser and emitter."""
 
-        document = CreoleParser(self.raw).parse()
-        result = Emitter(document, formatter, self.request, Macro(self)).emit()
+        document = CreoleParser(self.raw, self.rules).parse()
+        result = Emitter(document, formatter, self.request, Macro(self),
+                         self.rules).emit()
         self.request.write(result)
 
-class Rules:
+class MoinRules(CreoleRules):
     # For the link targets:
     proto = r'http|https|ftp|nntp|news|mailto|telnet|file|irc'
     extern = r'(?P<extern_addr>(?P<extern_proto>%s):.*)' % proto
@@ -81,6 +86,12 @@
         '''
     page = r'(?P<page_name> .* )'
 
+    def __init__(self, *args, **kwargs):
+        CreoleRules.__init__(self, *args, **kwargs)
+        # for addresses
+        self.addr_re = re.compile('|'.join([self.extern, self.attach,
+                                            self.interwiki, self.page]),
+                                  re.X | re.U)
 
 class Emitter:
     """
@@ -88,19 +99,13 @@
     tree consisting of DocNodes.
     """
 
-    addr_re = re.compile('|'.join([
-            Rules.extern,
-            Rules.attach,
-            Rules.interwiki,
-            Rules.page
-        ]), re.X | re.U) # for addresses
-
-    def __init__(self, root, formatter, request, macro):
+    def __init__(self, root, formatter, request, macro, rules):
         self.root = root
         self.formatter = formatter
         self.request = request
         self.form = request.form
         self.macro = macro
+        self.rules = rules
 
     def get_text(self, node):
         """Try to emit whatever text is in the node."""
@@ -259,7 +264,7 @@
 
     def link_emit(self, node):
         target = node.content
-        m = self.addr_re.match(target)
+        m = self.rules.addr_re.match(target)
         if m:
             if m.group('page_name'):
                 # link to a page