incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [2/2] git commit: work in progress on autolink wiht escapes
Date Wed, 13 Feb 2013 23:51:27 GMT
Updated Branches:
  refs/heads/db/5358 [created] 658e1c434


work in progress on autolink wiht escapes


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

Branch: refs/heads/db/5358
Commit: 658e1c434351eca02bfde7d6cc280c05279653ca
Parents: fdba00c
Author: Dave Brondsema <dbrondsema@geek.net>
Authored: Tue Feb 5 20:38:47 2013 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Wed Feb 13 23:50:27 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/markdown_extensions.py |    6 +++++-
 Allura/allura/tests/test_globals.py      |   12 ++++++++----
 2 files changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/658e1c43/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index c004db0..1f50876 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -38,7 +38,8 @@ class ForgeExtension(markdown.Extension):
         md.preprocessors['fenced-code'] = FencedCodeProcessor()
         md.preprocessors.add('plain_text_block', PlainTextPreprocessor(md), "_begin")
         md.preprocessors.add('macro_include', ForgeMacroIncludePreprocessor(md), '_end')
-        md.inlinePatterns['autolink_1'] = AutolinkPattern(r'(http(?:s?)://[a-zA-Z0-9./\-_0%?&=+#;~:]+)')
+        # this has to be before the 'escape' processor, otherwise weird placeholders are
inserted for escaped chars within urls, and then the autolink can't match the whole url
+        md.inlinePatterns.add('autolink_without_brackets', AutolinkPattern(r'(http(?:s?)://[a-zA-Z0-9./\-\\_%?&=+#;~:]+)'),
'<escape')
         # replace the link pattern with our extended version
         md.inlinePatterns['link'] = ForgeLinkPattern(markdown.inlinepatterns.LINK_RE, md,
ext=self)
         md.inlinePatterns['short_reference'] = ForgeLinkPattern(markdown.inlinepatterns.SHORT_REF_RE,
md, ext=self)
@@ -280,6 +281,9 @@ class AutolinkPattern(markdown.inlinepatterns.LinkPattern):
         old_link = mo.group(2)
         result = markdown.util.etree.Element('a')
         result.text = old_link
+        # since this is run before the builtin 'escape' processor, we have to do our own
unescaping
+        for char in markdown.Markdown.ESCAPED_CHARS:
+            old_link = old_link.replace('\\' + char, char)
         result.set('href', old_link)
         return result
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/658e1c43/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index cb53a0e..a11919c 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -259,14 +259,18 @@ def foo(): pass
 
 
 def test_markdown_autolink():
-    #with h.set_context('test', 'wiki', neighborhood='Projects')
-    text = g.markdown.convert('This is http://sf.net')
-    assert '<a href=' in text, text
+    assert '<a href=' in g.markdown.convert('This is http://sf.net')
     tgt = 'http://everything2.com/?node=nate+oostendorp'
     s = g.markdown.convert('This is %s' % tgt)
     assert_equal(
         s, '<div class="markdown_content"><p>This is <a href="%s" rel="nofollow">%s</a></p></div>'
% (tgt, tgt))
-    assert '<a href=' in g.markdown.convert('This is http://sf.net')
+
+
+def test_markdown_autolink_with_escape():
+    # \_ is unnecessary but valid markdown escaping and should be considered as a regular
underscore
+    # (it occurs during html2text conversion during project migrations)
+    r = g.markdown.convert('a http://www.phpmyadmin.net/home\_page/security/\#target b')
+    assert 'href="http://www.phpmyadmin.net/home_page/security/#target"' in r, r
 
 
 def test_macro_projects():


Mime
View raw message