changeset 2615:153b68947eb2

creole parser: do url escaping in a way that complete url gets escaped and // does not trigger italic
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 09 Aug 2007 10:20:04 +0200
parents 9a90c11c6c0d
children 95072cb86462
files MoinMoin/parser/text_creole.py
diffstat 1 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/parser/text_creole.py	Wed Aug 08 06:17:14 2007 +0200
+++ b/MoinMoin/parser/text_creole.py	Thu Aug 09 10:20:04 2007 +0200
@@ -113,7 +113,7 @@
 
     # For the inline elements:
     inline_tab = {
-        'url': r'''(^|(?<=\s|[.,:;!?()/=]))(?P<url_target>(?P<url_proto>http|ftp|mailto|irc|https|ftps|news|gopher|file|telnet|nntp):\S+?)($|(?=\s|[,.:;!?()](\s|$)))''',
+        'url': r'''(^|(?<=\s|[.,:;!?()/=]))(?P<escaped_url>~)?(?P<url_target>(?P<url_proto>http|ftp|mailto|irc|https|ftps|news|gopher|file|telnet|nntp):\S+?)($|(?=\s|[,.:;!?()](\s|$)))''',
         'link': r'\[\[(?P<link_target>.+?)\s*(\|\s*(?P<link_text>.+?)\s*)?]]',
         'image': r'{{(?P<image_target>.+?)\s*(\|\s*(?P<image_text>.+?)\s*)?}}',
         'macro': r'<<(?P<macro_target>.+?)\s*(\|\s*(?P<macro_text>.+?)\s*)?>>',
@@ -218,12 +218,19 @@
 
     def _url_repl(self, groups):
         """Handle raw urls in text."""
-        target = groups.get('url_target', '')
-        node = DocNode('external_link', self.cur)
-        node.content = target
-        node.proto = groups.get('url_proto', 'http')
-        DocNode('text', node, node.content)
-        self.text = None
+        if not groups.get('escaped_url'):
+            # this url is NOT escaped
+            target = groups.get('url_target', '')
+            node = DocNode('external_link', self.cur)
+            node.content = target
+            node.proto = groups.get('url_proto', 'http')
+            DocNode('text', node, node.content)
+            self.text = None
+        else:
+            # this url is escaped, we render it as text
+            if self.text is None:
+                self.text = DocNode('text', self.cur, u'')
+            self.text.content += groups.get('url_target')
     _url_target_repl = _url_repl
     _url_proto_repl = _url_repl