allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [8/8] git commit: [#4667] updates for new version of Markdown
Date Wed, 07 Nov 2012 21:00:48 GMT
[#4667] updates for new version of Markdown


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

Branch: refs/heads/master
Commit: a890ee43bc09382ff005cdb5fffab2fc92e55ce1
Parents: 16a641f
Author: Dave Brondsema <dbrondsema@geek.net>
Authored: Sat Sep 22 03:29:31 2012 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Wed Nov 7 20:30:55 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/app_globals.py         |    4 +-
 Allura/allura/lib/macro.py               |    9 ++++---
 Allura/allura/lib/markdown_extensions.py |   21 +++++++++++++--
 Allura/allura/tests/test_globals.py      |   33 ++++++++++++++----------
 4 files changed, 44 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a890ee43/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 6cf7f14..3e278ad 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -47,7 +47,7 @@ class ForgeMarkdown(markdown.Markdown):
         try:
             return markdown.Markdown.convert(self, source)
         except Exception as e:
-            log.info('Invalid markdown: %s %s', e, source)
+            log.info('Invalid markdown: %s', source, exc_info=True)
             escaped = h.really_unicode(source)
             escaped = cgi.escape(escaped)
             return h.html.literal(u"""<p><strong>ERROR!</strong> The markdown
supplied could not be parsed correctly.
@@ -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'],
+                extensions=['codehilite', ForgeExtension(**kwargs), 'tables', 'toc'], # 'nl2br',
'fenced_code'
                 output_format='html4')
 
     @property

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a890ee43/Allura/allura/lib/macro.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index e43b467..7b921eb 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -42,15 +42,16 @@ class parse(object):
                 args = dict(t.split('=', 1) for t in parts[1:])
                 response = macro(**h.encode_keys(args))
                 return response
-            except (ValueError, TypeError), ex:
+            except (ValueError, TypeError) as ex:
                 msg = cgi.escape(u'[[%s]] (%s)' % (s, repr(ex)))
+                log.warn('macro error', exc_info=True)
                 return '\n<div class="error"><pre><code>%s</code></pre></div>'
% msg
         except Exception, ex:
             raise
             return '[[Error parsing %s: %s]]' % (s, ex)
 
     def _lookup_macro(self, s):
-        macro, context = _macros.get(s, None)
+        macro, context = _macros.get(s, (None, None))
         if context is None or context == self._context:
             return macro
         else:
@@ -240,7 +241,7 @@ def projects(category=None, display_mode='grid', sort='last_updated',
         columns=1, show_proj_icon=True, show_download_button=True, show_awards_banner=True,
         grid_view_tools=''):
     initial_q = dict(neighborhood_id=c.project.neighborhood_id)
-    return get_projects_for_macro(category=category, display_mode=display_mode, sort=sort,

+    return get_projects_for_macro(category=category, display_mode=display_mode, sort=sort,
                    show_total=show_total, limit=limit, labels=labels, award=award, private=private,
                    columns=columns, show_proj_icon=show_proj_icon, show_download_button=show_download_button,
                    show_awards_banner=show_awards_banner, grid_view_tools=grid_view_tools,
@@ -261,7 +262,7 @@ def my_projects(category=None, display_mode='grid', sort='last_updated',
         ids.append(p._id)
 
     initial_q = dict(_id={'$in': ids})
-    return get_projects_for_macro(category=category, display_mode=display_mode, sort=sort,

+    return get_projects_for_macro(category=category, display_mode=display_mode, sort=sort,
                    show_total=show_total, limit=limit, labels=labels, award=award, private=private,
                    columns=columns, show_proj_icon=show_proj_icon, show_download_button=show_download_button,
                    show_awards_banner=show_awards_banner, grid_view_tools=grid_view_tools,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a890ee43/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 2f7b2f3..eac8b1c 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -128,8 +128,14 @@ class ForgeProcessor(object):
         if self.macro_re.match(raw):
             stash = 'macro'
             raw = raw[1:-1] # strip off the enclosing []
-        elif self.artifact_re.match(raw): stash = 'artifact'
-        else: return raw
+        elif raw == 'TOC':
+            # pass this straight through and don't do an artifact lookup
+            return '[' + raw + ']'
+        elif self.artifact_re.match(raw):
+            stash = 'artifact'
+        else:
+            return raw
+        print 'store', stash, raw
         return self._store(stash, raw)
 
     def _store(self, stash_name, value):
@@ -139,7 +145,9 @@ class ForgeProcessor(object):
 
     def lookup(self, stash, id):
         stash = self.stash.get(stash, [])
-        if id >= len(stash): return ''
+        if id >= len(stash):
+            return ''
+        print 'lookup returning', stash[id]
         return stash[id]
 
     def compile(self):
@@ -152,7 +160,9 @@ class ForgeProcessor(object):
                 self.alinks = {}
         self.stash['artifact'] = map(self._expand_alink, self.stash['artifact'])
         self.stash['link'] = map(self._expand_link, self.stash['link'])
+        print 'pre:', self.stash['macro']
         self.stash['macro'] = map(macro.parse(self._macro_context), self.stash['macro'])
+        print 'post:', self.stash['macro']
 
     def reset(self):
         self.stash = dict(
@@ -200,7 +210,12 @@ class ForgePostprocessor(markdown.postprocessors.Postprocessor):
 
     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)
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/a890ee43/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 99f7923..b528cab 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -111,16 +111,6 @@ def test_macros():
         assert '<img alt="test2 Logo"' in r, r
         assert '<img alt="test Logo"' not in r, r
         assert '<img alt="sub1 Logo"' not in r, r
-        r = g.markdown_wiki.convert("""[TOC]
-
-# Header 1
-
-## Header 2""")
-        assert '<a class="" href="#header-1">Header 1</a>' in r, r
-
-        r = g.markdown_wiki.convert("""  <?xml version="1.0" encoding="UTF-8"?>
-  <project xmlns="0"></project>""")
-        assert 'The markdown supplied could not be parsed correctly.' in r, r
 
         r = g.markdown_wiki.convert('[[projects show_proj_icon=True]]')
         assert '<img alt="test Logo"' in r
@@ -128,8 +118,6 @@ def test_macros():
         assert '<img alt="test Logo"' not in r
 
     c.project = curr_project
-    r = g.markdown_wiki.convert('[[project_admins]]')
-    assert r == '<div class="markdown_content"><p><a href="/u/test-admin/">Test
Admin</a><br /></p></div>'
     r = g.markdown_wiki.convert('[[download_button]]')
     assert_equal(r, '<div class="markdown_content"><p><span class="download-button-%s"
style="margin-bottom: 1em; display: block;"></span></p></div>' % p_test._id)
     h.set_context('--init--', 'wiki', neighborhood='Projects')
@@ -157,6 +145,23 @@ def test_macros():
     r = g.markdown_wiki.convert('[[neighborhood_blog_posts]]')
     assert 'test content' in r
 
+def test_macro_project_admins():
+    r = g.markdown_wiki.convert('[[project_admins]]')
+    assert_equal(r, '<div class="markdown_content"><p><a href="/u/test-admin/">Test
Admin</a><br /></p></div>')
+
+def test_markdown_toc():
+    r = g.markdown_wiki.convert("""[TOC]
+
+# Header 1
+
+## Header 2""")
+    assert '<a class="" href="#header-1">Header 1</a>' in r, r
+
+def test_markdown_xml_error():
+    r = g.markdown_wiki.convert("""  <?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="0"></project>""")
+    assert 'The markdown supplied could not be parsed correctly.' in r, r
+
 @with_setup(setUp)
 def test_markdown():
     'Just a test to get coverage in our markdown extension'
@@ -317,9 +322,9 @@ def test_hideawards_macro():
 
     with h.push_context(p_nbhd.neighborhood_project._id):
         r = g.markdown_wiki.convert('[[projects]]')
-        assert '<div class="feature">Award short</div>' in r
+        assert '<div class="feature">Award short</div>' in r, r
         r = g.markdown_wiki.convert('[[projects show_awards_banner=False]]')
-        assert '<div class="feature">Award short</div>' not in r
+        assert '<div class="feature">Award short</div>' not in r, r
 
 def get_project_names(r):
     """


Mime
View raw message