Repository: allura
Updated Branches:
refs/heads/je/42cc_4771 [created] dd961bc4f
[#4771] ticket:635 Fix bugs catched by tests
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/6cc40c67
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/6cc40c67
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/6cc40c67
Branch: refs/heads/je/42cc_4771
Commit: 6cc40c674789121154c63d2ce7ba0f187666c886
Parents: 3724618
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Aug 26 13:46:47 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Aug 26 13:47:41 2014 +0300
----------------------------------------------------------------------
Allura/allura/lib/app_globals.py | 5 ++++-
Allura/allura/lib/markdown_extensions.py | 15 ++++++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/6cc40c67/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 9c80253..29b2db1 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -35,6 +35,7 @@ import traceback
import activitystream
import pkg_resources
import markdown
+from markdown.extensions.toc import TocExtension
import pygments
import pygments.lexers
import pygments.formatters
@@ -54,6 +55,7 @@ from allura import model as M
from allura.lib.markdown_extensions import (
ForgeExtension,
CommitMessageExtension,
+ slugify,
)
from allura.eventslistener import PostEvent
@@ -443,11 +445,12 @@ class Globals(object):
def forge_markdown(self, **kwargs):
'''return a markdown.Markdown object on which you can call convert'''
+ toc = TocExtension(configs=[('slugify', slugify)])
return ForgeMarkdown(
# 'fenced_code'
extensions=['codehilite',
ForgeExtension(
- **kwargs), 'tables', 'toc', 'nl2br'],
+ **kwargs), 'tables', toc, 'nl2br'],
output_format='html4')
@property
http://git-wip-us.apache.org/repos/asf/allura/blob/6cc40c67/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index e4ca61c..f2f8871 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -25,6 +25,7 @@ import html5lib
import html5lib.serializer
import html5lib.filters.alphabeticalattributes
import markdown
+from markdown.extensions.headerid import slugify as headerid_slugify
from . import macro
from . import helpers as h
@@ -41,6 +42,12 @@ PLAINTEXT_BLOCK_RE = re.compile(
MACRO_PATTERN = r'\[\[([^\]\[]+)\]\]'
+def slugify(value, separator):
+ value = h.really_unicode(value)
+ separator = h.really_unicode(separator)
+ return headerid_slugify(value, separator)
+
+
class CommitMessageExtension(markdown.Extension):
"""Markdown extension for processing commit messages.
@@ -416,7 +423,13 @@ class ForgeMacroPattern(markdown.inlinepatterns.Pattern):
# etree.fromstring parses html with newlines into empty div somehow
html = [l.strip() for l in html.splitlines() if l.strip()]
html = ''.join(html)
- return markdown.util.etree.fromstring(html)
+ try:
+ html = markdown.util.etree.fromstring(html)
+ except Exception:
+ # perhaps it is something like macro error which isn't parsable to html
+ # (e.g. "[[include: you don't have a read permission for...")
+ pass
+ return html
placeholder = self.markdown.htmlStash.store(html)
return placeholder
[#4771] ticket:635 Add test for TOC for included pages
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/d517f0c5
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/d517f0c5
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/d517f0c5
Branch: refs/heads/je/42cc_4771
Commit: d517f0c58674ffd25a00807b7badd0fb2dc5cf6d
Parents: 608090e
Author: Igor Bondarenko <je...@gmail.com>
Authored: Wed Aug 20 13:00:12 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Aug 26 13:47:41 2014 +0300
----------------------------------------------------------------------
Allura/allura/tests/test_globals.py | 44 ++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/d517f0c5/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 5dc0e43..d6ccfe1 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -488,6 +488,50 @@ def test_macro_include():
assert 'href="..' not in g.markdown.convert('[My foo](./foo)')
+@td.with_wiki
+def test_toc_generation_for_included_page():
+ parent_text = u'''
+[TOC]
+
+#heading in original page
+
+Sample text
+
+#another in original page
+
+More sample text
+
+[[include ref=included]]
+'''
+ included_text = u'''
+#heading for included page
+
+Sample
+
+#another heading for included page
+
+More text
+'''
+ p_nbhd = M.Neighborhood.query.get(name='Projects')
+ p_test = M.Project.query.get(shortname='test', neighborhood_id=p_nbhd._id)
+ wiki = p_test.app_instance('wiki')
+ with h.push_context(p_test._id, app_config_id=wiki.config._id):
+ p = WM.Page.upsert(title='included')
+ p.text = included_text
+ p.commit()
+ ThreadLocalORMSession.flush_all()
+
+ result = g.markdown.convert(parent_text)
+ assert_in(u'<li><a href="#heading-in-original-page">'
+ u'heading in original page</a></li>', result)
+ assert_in(u'<li><a href="#another-in-original-page">'
+ u'another in original page</a></li>', result)
+ assert_in(u'<li><a href="#heading-for-included-page">'
+ u'heading for included page</a></li>', result)
+ assert_in(u'<li><a href="#another-heading-for-included-page">'
+ u'another heading for included page</a></li>', result)
+
+
def test_macro_nbhd_feeds():
with h.push_context('--init--', 'wiki', neighborhood='Projects'):
r = g.markdown_wiki.convert('[[neighborhood_feeds tool_name=wiki]]')
[#4771] ticket:635 Fix TOC generation for included pages
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/37246180
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/37246180
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/37246180
Branch: refs/heads/je/42cc_4771
Commit: 372461803363715fb1bf33e0f707478c1b9a6894
Parents: d517f0c
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Aug 21 17:36:28 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Aug 26 13:47:41 2014 +0300
----------------------------------------------------------------------
Allura/allura/lib/markdown_extensions.py | 6 ++++++
1 file changed, 6 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/37246180/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 055a74a..e4ca61c 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -412,6 +412,12 @@ class ForgeMacroPattern(markdown.inlinepatterns.Pattern):
def handleMatch(self, m):
html = self.macro(m.group(2))
+ if m.group(2).startswith('include'):
+ # etree.fromstring parses html with newlines into empty div somehow
+ html = [l.strip() for l in html.splitlines() if l.strip()]
+ html = ''.join(html)
+ return markdown.util.etree.fromstring(html)
+
placeholder = self.markdown.htmlStash.store(html)
return placeholder
's that markdown inserts Posted by je...@apache.org.
[#4771] ticket:635 Get rid of extra <p>'s that markdown inserts
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/72227003
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/72227003
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/72227003
Branch: refs/heads/je/42cc_4771
Commit: 72227003cd3b3e0d197769a064638e6aa16314e1
Parents: 6cc40c6
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Aug 26 16:34:26 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Aug 26 16:34:26 2014 +0300
----------------------------------------------------------------------
Allura/allura/lib/markdown_extensions.py | 42 +++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/72227003/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index f2f8871..024eca1 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -278,6 +278,8 @@ class ForgeExtension(markdown.Extension):
'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.add(
+ 'macro_include', ForgeMacroIncludeTreeProcessor(md), '_end')
# Sanitize HTML
md.postprocessors['sanitize_html'] = HTMLSanitizer()
# Rewrite all relative links that don't start with . to have a '../'
@@ -581,3 +583,43 @@ class ForgeMacroIncludePreprocessor(markdown.preprocessors.Preprocessor):
buf = []
result.append(line)
return result
+
+
+class ForgeMacroIncludeTreeProcessor(markdown.treeprocessors.Treeprocessor):
+ '''Remove extra <p> in which included page is wrapped.
+
+ Because it adds extra space between parent page content and included page content,
+ which looks ugly.
+
+ Convert:
+ <p><div><div class="markdown_content">...</div></div></p>
+
+ To:
+ <div class="markdown_content">...</div>
+ '''
+
+ def _get_include(self, p):
+ children = p.getchildren()
+ if len(children) != 1 or children[0].tag != 'div':
+ return
+ children = children[0].getchildren()
+ if len(children) != 1 or children[0].tag != 'div':
+ return
+ if children[0].get('class') == 'markdown_content':
+ return children[0]
+
+ def run(self, root):
+ p_with_parent = [(tag, parent)
+ for parent in root.getiterator()
+ for tag in parent
+ if tag.tag == 'p']
+ replace = []
+ for p, parent in p_with_parent:
+ include = self._get_include(p)
+ if include:
+ idx = parent.getchildren().index(p)
+ replace.append((p, parent, idx, include)) # (what, parent, index in parent, replacement)
+ for what, parent, i, replacement in replace:
+ parent.remove(what)
+ parent.insert(i, replacement)
+ return root
'cause
[#4771] ticket:635 Don't strip wrapping <div> together with <p> 'cause <div> is important
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/dd961bc4
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/dd961bc4
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/dd961bc4
Branch: refs/heads/je/42cc_4771
Commit: dd961bc4fbc4b6781dd15f2344a01e26d7f06659
Parents: 7222700
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Aug 26 16:48:59 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Tue Aug 26 16:48:59 2014 +0300
----------------------------------------------------------------------
Allura/allura/lib/markdown_extensions.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/dd961bc4/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 024eca1..5b0542d 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -595,18 +595,19 @@ class ForgeMacroIncludeTreeProcessor(markdown.treeprocessors.Treeprocessor):
<p><div><div class="markdown_content">...</div></div></p>
To:
- <div class="markdown_content">...</div>
+ <div><div class="markdown_content">...</div></div>
'''
def _get_include(self, p):
children = p.getchildren()
if len(children) != 1 or children[0].tag != 'div':
return
- children = children[0].getchildren()
+ parent = children[0]
+ children = parent.getchildren()
if len(children) != 1 or children[0].tag != 'div':
return
if children[0].get('class') == 'markdown_content':
- return children[0]
+ return parent
def run(self, root):
p_with_parent = [(tag, parent)