You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2014/10/30 12:20:56 UTC
[06/11] git commit: [#4771] ticket:635 Fix bugs catched by tests
[#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/1c7d6278
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/1c7d6278
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/1c7d6278
Branch: refs/heads/ib/4771
Commit: 1c7d627894111c2cb41774af2312d047eedff72d
Parents: 1a745a0
Author: Igor Bondarenko <je...@gmail.com>
Authored: Tue Aug 26 13:46:47 2014 +0300
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Oct 30 09:44:22 2014 +0000
----------------------------------------------------------------------
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/1c7d6278/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 2d5136e..50abc49 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
@@ -442,11 +444,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/1c7d6278/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