incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject git commit: [#5245] use the standard nl2br extension instead of our own
Date Fri, 09 Nov 2012 01:18:25 GMT
Updated Branches:
  refs/heads/db/5245 e1b445ade -> d68805919


[#5245] use the standard nl2br extension instead of our own

Our own wasn't creating breaks if a line contained an escaped
markdown syntax character, e.g. \(

This also removes errors when handling various inputs


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

Branch: refs/heads/db/5245
Commit: d6880591995a39b3f3616d602a702068e55d4baa
Parents: e1b445a
Author: Dave Brondsema <dbrondsema@geek.net>
Authored: Fri Nov 9 01:16:19 2012 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Fri Nov 9 01:17:39 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/app_globals.py         |    2 +-
 Allura/allura/lib/markdown_extensions.py |   36 -------------------------
 Allura/allura/tests/test_globals.py      |    5 +--
 3 files changed, 3 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d6880591/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 3e278ad..55ebf5d 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -307,7 +307,7 @@ class Globals(object):
     def forge_markdown(self, **kwargs):
         '''return a markdown.Markdown object on which you can call convert'''
         return ForgeMarkdown(
-                extensions=['codehilite', ForgeExtension(**kwargs), 'tables', 'toc'], # 'nl2br',
'fenced_code'
+                extensions=['codehilite', ForgeExtension(**kwargs), 'tables', 'toc', 'nl2br'],
# 'fenced_code'
                 output_format='html4')
 
     @property

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d6880591/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 96a495d..6454df5 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -43,7 +43,6 @@ class ForgeExtension(markdown.Extension):
         md.inlinePatterns.add('macro', ForgeMacroPattern(MACRO_PATTERN, md, ext=self), '<link')
         self.forge_link_tree_processor = ForgeLinkTreeProcessor(md)
         md.treeprocessors['links'] = self.forge_link_tree_processor
-        md.treeprocessors['br'] = LineOrientedTreeProcessor(md)
         # Sanitize HTML
         md.postprocessors['sanitize_html'] = HTMLSanitizer()
         # Rewrite all relative links that don't start with . to have a '../' prefix
@@ -256,41 +255,6 @@ class HTMLSanitizer(markdown.postprocessors.Postprocessor):
         return unicode(p.output(), 'utf-8')
 
 
-class LineOrientedTreeProcessor(markdown.treeprocessors.Treeprocessor):
-    '''Once MD is satisfied with the etree, this runs to replace \n with <br/>
-    within <p>s.
-    '''
-
-    def __init__(self, md):
-        self._markdown = md
-
-    def run(self, root):
-        for node in root.getiterator('p'):
-            if not node.text: continue
-            if '\n' not in node.text: continue
-            text = self._markdown.serializer(node)
-            text = self._markdown.postprocessors['raw_html'].run(text)
-            text = text.strip().encode('utf-8')
-            if '\n' not in text: continue
-            new_text = (text
-                        .replace('<br>', '<br/>')
-                        .replace('\n', '<br/>'))
-            new_node = None
-            try:
-                new_node = markdown.util.etree.fromstring(new_text)
-            except SyntaxError:
-                try:
-                    new_node = markdown.util.etree.fromstring(unicode(BeautifulSoup(new_text)))
-                except:
-                    log.exception('Error adding <br> tags: new text is %s', new_text)
-                    pass
-            if new_node:
-                node.clear()
-                node.text = new_node.text
-                node[:] = list(new_node)
-        return root
-
-
 class AutolinkPattern(markdown.inlinepatterns.LinkPattern):
 
     def handleMatch(self, mo):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/d6880591/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 8e17731..57422f1 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -181,9 +181,8 @@ def test_markdown_links():
     text = g.markdown.convert('See [test:wiki:Home]')
     assert '<a class="alink" href="/p/test/wiki/Home/">[test:wiki:Home]</a>'
in text, text
 
-def test_markdown_xml_error():
-    r = g.markdown_wiki.convert("""  <?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="0"></project>""")
+def test_markdown_error():
+    r = g.markdown_wiki.convert('[:::]')
     assert 'The markdown supplied could not be parsed correctly.' in r, r
 
 @with_setup(setUp)


Mime
View raw message