changeset 3390:f1ba94b7913d

GUI editor: fixed javascript error by using a simpler word_rule_js regex
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 21 Mar 2008 13:31:24 +0100
parents df4f538f8e8f
children eea0edb31d9d
files MoinMoin/PageGraphicalEditor.py MoinMoin/parser/text_moin_wiki.py
diffstat 2 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/PageGraphicalEditor.py	Fri Mar 21 12:51:01 2008 +0100
+++ b/MoinMoin/PageGraphicalEditor.py	Fri Mar 21 13:31:24 2008 +0100
@@ -35,7 +35,7 @@
     """ Same as PageEditor, but use the GUI editor (FCKeditor) """
     def word_rule(self):
         regex = re.compile(r"\(\?<![^)]*?\)")
-        word_rule = regex.sub("", WikiParser.word_rule)
+        word_rule = regex.sub("", WikiParser.word_rule_js)
         return repr(word_rule)[1:]
 
     def sendEditor(self, **kw):
--- a/MoinMoin/parser/text_moin_wiki.py	Fri Mar 21 12:51:01 2008 +0100
+++ b/MoinMoin/parser/text_moin_wiki.py	Fri Mar 21 13:31:24 2008 +0100
@@ -76,6 +76,7 @@
         'punct': punct_pattern,
     }
 
+    # BE CAREFUL: if you do changes to word_rule, consider doing them also to word_rule_js (see below)
     word_rule = ur'''
         (?:
          (?<![%(u)s%(l)s/])  # require anything not upper/lower/slash before
@@ -109,6 +110,22 @@
         'child': re.escape(CHILD_PREFIX),
         'parent': re.escape(PARENT_PREFIX),
     }
+    # simplified word_rule for FCKeditor's "unlink" plugin (puts a ! in front of a WikiName if WikiName matches word_rule_js),
+    # because JavaScript can not use group names and verbose regular expressions!
+    word_rule_js = (
+        ur'''(?:(?<![%(u)s%(l)s/])|^)'''
+        ur'''(?:'''
+         ur'''(?:(%(parent)s)*|((?<!%(child)s)%(child)s)?)'''
+         ur'''(((?<!%(child)s)%(child)s)?(?:[%(u)s][%(l)s]+){2,})+'''
+         ur'''(?:\#(?:\S+))?'''
+        ur''')'''
+        ur'''(?:(?![%(u)s%(l)s/])|$)'''
+    ) % {
+        'u': config.chars_upper,
+        'l': config.chars_lower,
+        'child': re.escape(CHILD_PREFIX),
+        'parent': re.escape(PARENT_PREFIX),
+    }
 
     # link targets:
     extern_rule = r'(?P<extern_addr>(?P<extern_scheme>%s)\:.*)' % url_scheme