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:21:00 UTC
[10/11] git commit: [#4771] ticket:672 (Almost) fix the case when
included page contains 's
[#4771] ticket:672 (Almost) fix the case when included page contains <pre>'s
<pre> tags included in the page, which included in another page now looks correct,
as well as line numbers. But code still gets extra <br>'s and looks weird :(
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/89070c4b
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/89070c4b
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/89070c4b
Branch: refs/heads/ib/4771
Commit: 89070c4bc49675af21426fe51e6390528f9055f2
Parents: 24b90e1
Author: Igor Bondarenko <je...@gmail.com>
Authored: Thu Oct 30 10:49:17 2014 +0000
Committer: Igor Bondarenko <je...@gmail.com>
Committed: Thu Oct 30 10:49:17 2014 +0000
----------------------------------------------------------------------
Allura/allura/lib/markdown_extensions.py | 28 +++++++++++++++------------
1 file changed, 16 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/89070c4b/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index 62445ef..f4306d9 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -101,6 +101,7 @@ class CommitMessageExtension(markdown.Extension):
# Put a class around markdown content for custom css
md.postprocessors['add_custom_class'] = AddCustomClass()
md.postprocessors['mark_safe'] = MarkAsSafe()
+ md.postprocessors['newlines_inside_pre'] = ReplaceNewlinesInsidePre()
def reset(self):
self.forge_link_tree_processor.reset()
@@ -289,6 +290,7 @@ class ForgeExtension(markdown.Extension):
# Put a class around markdown content for custom css
md.postprocessors['add_custom_class'] = AddCustomClass()
md.postprocessors['mark_safe'] = MarkAsSafe()
+ md.postprocessors['newlines_inside_pre'] = ReplaceNewlinesInsidePre()
def reset(self):
self.forge_link_tree_processor.reset()
@@ -432,18 +434,15 @@ class ForgeMacroPattern(markdown.inlinepatterns.Pattern):
Also, preserve formatting inside <pre>'s.
'''
result = []
- _inside_pre = False
- for line in html.splitlines(True):
- if '<pre>' in line:
- _inside_pre = True
- if '</pre>' in line:
- _inside_pre = False
-
- if _inside_pre:
- result.append(line)
- elif line.strip():
- result.append(line.strip())
-
+ html = BeautifulSoup(html)
+ pres = html.findAll('pre')
+ for pre in pres:
+ #if pre.parent and pre.parent.get('class') == 'codehilite':
+ #continue
+ no_nl = unicode(pre).replace('\n', '#ALLURA-NEWLINE-INSIDE-PRE#')
+ no_nl = no_nl.replace('<pre>', '').replace('</pre>', '')
+ pre.string = h.html.literal(no_nl)
+ result = [line.strip() for line in unicode(html).splitlines() if line.strip()]
return ''.join(result)
def handleMatch(self, m):
@@ -578,6 +577,11 @@ class HTMLSanitizer(markdown.postprocessors.Postprocessor):
return out
+class ReplaceNewlinesInsidePre(markdown.postprocessors.Postprocessor):
+ def run(self, text):
+ return text.replace('#ALLURA-NEWLINE-INSIDE-PRE#', '\n')
+
+
class AutolinkPattern(markdown.inlinepatterns.Pattern):
def __init__(self, pattern, markdown_instance=None):