allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [27/44] git commit: [#4667] start work: change Forge markdown extensions to inline patterns instead of matching pre-/post- which don't work with the new version of Markdown and the toc extension
Date Tue, 27 Nov 2012 13:46:06 GMT
[#4667] start work: change Forge markdown extensions to inline patterns instead of matching
pre-/post- which don't work with the new version of Markdown and the toc extension


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/31b8b502
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/31b8b502
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/31b8b502

Branch: refs/heads/cj/4691
Commit: 31b8b50252c1cd6448aab135e43486a3cd6b93f9
Parents: a890ee4
Author: Dave Brondsema <dbrondsema@geek.net>
Authored: Mon Sep 24 14:19:07 2012 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Wed Nov 7 20:30:56 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/markdown_extensions.py |   37 +++++++++++--------------
 1 files changed, 16 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/31b8b502/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index eac8b1c..6156b62 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -25,6 +25,7 @@ PLAINTEXT_BLOCK_RE = re.compile( \
     re.MULTILINE|re.DOTALL
     )
 
+
 class ForgeExtension(markdown.Extension):
 
     def __init__(self, wiki=False, email=False, macro_context=None):
@@ -40,6 +41,8 @@ class ForgeExtension(markdown.Extension):
         md.preprocessors['fenced-code'] = FencedCodeProcessor()
         md.preprocessors.add('plain_text_block', PlainTextPreprocessor(md), "_begin")
         md.inlinePatterns['autolink_1'] = AutolinkPattern(r'(http(?:s?)://[a-zA-Z0-9./\-_0%?&=+#;~:]+)')
+        # replace the link pattern with our extended version
+        md.inlinePatterns['link'] = ForgeLinkPattern(markdown.inlinepatterns.LINK_RE, md)
         md.treeprocessors['br'] = LineOrientedTreeProcessor(md)
         # Sanitize HTML
         md.postprocessors['sanitize_html'] = HTMLSanitizer()
@@ -53,6 +56,18 @@ class ForgeExtension(markdown.Extension):
     def reset(self):
         self.forge_processor.reset()
 
+class ForgeLinkPattern(markdown.inlinepatterns.LinkPattern):
+
+    artifact_re = re.compile(r'((.*?):)?((.*?):)?(.+)')
+
+    def sanitize_url(self, url):
+        url = markdown.inlinepatterns.Pattern.sanitize_url(url)
+        log.warn('url is %s' % url)
+        log.info('url is %s' % url)
+        if not url and self.artifact_re.match(url):
+            url = 'LINK %s LINK' % url
+        return url
+
 class PlainTextPreprocessor(markdown.preprocessors.Preprocessor):
     '''
     This was used earlier for [plain] tags that the Blog tool's rss importer
@@ -98,7 +113,6 @@ class FencedCodeProcessor(markdown.preprocessors.Preprocessor):
         return new_lines
 
 class ForgeProcessor(object):
-    alink_pattern = r'(?<!\[)\[([^\]\[]*)\]'
     macro_pattern = r'\[(\[([^\]\[]*)\])\]'
     placeholder_prefix = '#jgimwge'
     placeholder = '%s:%%s:%%.4d#khjhhj' % placeholder_prefix
@@ -109,13 +123,11 @@ class ForgeProcessor(object):
         self._use_wiki = use_wiki
         self._macro_context = macro_context
         self.inline_patterns = {
-            'forge.alink' : ForgeInlinePattern(self, self.alink_pattern),
             'forge.macro' : ForgeInlinePattern(self, self.macro_pattern)}
-        self.postprocessor = ForgePostprocessor(self)
         self.tree_processor = ForgeTreeProcessor(self)
         self.reset()
         self.artifact_re = re.compile(r'((.*?):)?((.*?):)?(.+)')
-        self.macro_re = re.compile(self.alink_pattern)
+        self.macro_re = re.compile(self.alink_pattern) # BUG
 
     def install(self):
         for k,v in self.inline_patterns.iteritems():
@@ -201,23 +213,6 @@ class ForgeInlinePattern(markdown.inlinepatterns.Pattern):
     def handleMatch(self, m):
         return self.parent.store(m.group(2))
 
-class ForgePostprocessor(markdown.postprocessors.Postprocessor):
-
-    def __init__(self, parent):
-        self.parent = parent
-        markdown.postprocessors.Postprocessor.__init__(
-            self, parent.markdown)
-
-    def run(self, text):
-        self.parent.compile()
-        print
-        print 1, text
-        def repl(mo):
-            print 2, mo.group(1)
-            print 3, mo.group(2)
-            print 4, self.parent.lookup(mo.group(1), int(mo.group(2)))
-            return self.parent.lookup(mo.group(1), int(mo.group(2)))
-        return self.parent.placeholder_re.sub(repl, text)
 
 class ForgeTreeProcessor(markdown.treeprocessors.Treeprocessor):
     '''This flags intra-wiki links that point to non-existent pages'''


Mime
View raw message