You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2012/12/07 23:26:36 UTC

[39/49] git commit: [#5316] allow markdown within html tags, and document it

[#5316] allow markdown within html tags, and document it


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

Branch: refs/heads/db/4803
Commit: cb6a9e3725f2af6562c1cd580234255f211f6c7b
Parents: af0c0b4
Author: Dave Brondsema <db...@geek.net>
Authored: Thu Nov 29 23:17:35 2012 +0000
Committer: Cory Johns <jo...@geek.net>
Committed: Mon Dec 3 20:07:15 2012 +0000

----------------------------------------------------------------------
 Allura/allura/lib/markdown_extensions.py      |    2 +
 Allura/allura/templates/jinja_master/lib.html |   32 ++++++++++++-------
 Allura/allura/tests/test_globals.py           |   10 ++++++
 3 files changed, 32 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cb6a9e37/Allura/allura/lib/markdown_extensions.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/markdown_extensions.py b/Allura/allura/lib/markdown_extensions.py
index b34aa6a..0a5f75d 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -33,6 +33,8 @@ class ForgeExtension(markdown.Extension):
 
     def extendMarkdown(self, md, md_globals):
         md.registerExtension(self)
+        # allow markdown within e.g. <div markdown>...</div>  More info at: https://github.com/waylan/Python-Markdown/issues/52
+        md.preprocessors['html_block'].markdown_in_raw = True
         md.preprocessors['fenced-code'] = FencedCodeProcessor()
         md.preprocessors.add('plain_text_block', PlainTextPreprocessor(md), "_begin")
         md.inlinePatterns['autolink_1'] = AutolinkPattern(r'(http(?:s?)://[a-zA-Z0-9./\-_0%?&=+#;~:]+)')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cb6a9e37/Allura/allura/templates/jinja_master/lib.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/lib.html b/Allura/allura/templates/jinja_master/lib.html
index 7bfdddc..239f66f 100644
--- a/Allura/allura/templates/jinja_master/lib.html
+++ b/Allura/allura/templates/jinja_master/lib.html
@@ -120,7 +120,7 @@
     <li><a href="#md_ex_links{{id}}">Links</a></li>
     <li><a href="#md_ex_reflinks{{id}}">Reference Links</a></li>
     <li><a href="#md_ex_artlinks{{id}}">Artifact Links</a></li>
-    <li><a href="#md_ex_text{{id}}">Text</a></li>
+    <li><a href="#md_ex_text{{id}}">Basic Text Formatting</a></li>
     <li><a href="#md_ex_bq{{id}}">Blockquotes</a></li>
     <li><a href="#md_ex_pre{{id}}">Preformatted Text</a></li>
     <li><a href="#md_ex_lists{{id}}">Lists</a></li>
@@ -128,7 +128,7 @@
     <li><a href="#md_ex_headers{{id}}">Headers</a></li>
     <li><a href="#md_ex_hr{{id}}">Horizontal Rules</a></li>
     <li><a href="#md_ex_img{{id}}">Images</a></li>
-    <li><a href="#md_ex_escapes{{id}}">Escapes</a></li>
+    <li><a href="#md_ex_escapes{{id}}">Escapes and HTML</a></li>
     <li><a href="#md_ex_moreheaders{{id}}">More Headers</a></li>
     <li><a href="#md_ex_toc{{id}}">Table of Contents</a></li>
     <li><a href="#md_ex_code{{id}}">Code Highlighting</a></li>
@@ -226,7 +226,7 @@ You can even link to tickets in a subproject with `[subproject.tickets:#123]`.</
 </div>
 
 <div class="markdown_syntax_section hidden_in_modal md_ex_text{{id}}">
-<h2 id="md_ex_text{{id}}">Text</h2>
+<h2 id="md_ex_text{{id}}">Basic Text Formatting</h2>
 <p>Use * or _ to emphasize things:</p>
 <div class="codehilite"><pre>*this is in italic*  and _so is this_
 
@@ -484,7 +484,7 @@ image.</p>
 
 
 <div class="markdown_syntax_section hidden_in_modal md_ex_escapes{{id}}">
-<h2 id="md_ex_escapes{{id}}">Escapes</h2>
+<h2 id="md_ex_escapes{{id}}">Escapes and HTML</h2>
 <p>What if you want to just show asterisks, not italics?</p>
 <div class="codehilite"><pre>* this shows up in italics: *a happy day*
 * this shows the asterisks: \*a happy day\*
@@ -494,22 +494,30 @@ image.</p>
 {{g.markdown.convert('''* this shows up in italics: *a happy day*
 * this shows the asterisks: \*a happy day\*''')}}
 
-<p>The backslashes will disappear and leave the asterisks.</p>
-<p>You can do the same with any of the characters that have a special meaning<br>for Markdown.</p>
-<p>HTML tags may need to be escaped.  &lt;b&gt; will be interpreted as a bold tag.  Entity codes will be used.
-&lt;foobar&gt; isn't allowed and will be dropped, so you probably want to escape it:</p>
+<p>The backslashes will disappear and leave the asterisks.  You can do the same with any of the
+characters that have a special meaning<br>for Markdown.</p>
+
+<p>Many simple HTML tags are allowed, for example &lt;b&gt;  And unknown tags will be dropped.
+To show a literal &lt;b&gt; or an unknown tag like &lt;foobar&gt; you need escape it with
+HTML entities:
+:</p>
 <div class="codehilite"><pre>
 &lt;b&gt;this will be bold&lt;/b&gt;
 you should escape &amp;lt;unknown&amp;gt; tags
-&amp;lt; special entities work
-&amp;amp;lt; if you want to escape it
+&amp;copy; special entities work
+&amp;amp;copy; if you want to escape it
 </pre></div>
 
 <p>Output:</p>
 {{g.markdown.convert('''<b>this will be bold</b>
 you should escape &lt;unknown&gt; tags
-&lt; special entities work
-&amp;lt; if you want to escape it''')}}
+&copy; special entities work
+&amp;copy; if you want to escape it''')}}
+
+<p>HTML tags that are block-level like &lt;div&gt; can be used, but if there is markdown formatting
+within it, you must add a "markdown" attribute: &lt;div markdown&gt;  Some safe attributes are also
+allowed, permitting basic styling and layout: &lt;div markdown style="float:left"&gt;</p>
+
 <p>Individual ampersands (&amp;) and less-than signs (&lt;) are fine, they will be shown as expected.</p>
 </div>
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/cb6a9e37/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 111ebd8..57f65d8 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -185,6 +185,16 @@ def test_markdown_error():
     r = g.markdown_wiki.convert('[:::]')
     assert 'The markdown supplied could not be parsed correctly.' in r, r
 
+def test_markdown_and_html():
+    r = g.markdown_wiki.convert('<div style="float:left">blah</div>')
+    assert '<div style="float: left;">blah</div>' in r, r
+
+def test_markdown_within_html():
+    r = g.markdown_wiki.convert('<div style="float:left" markdown>**blah**</div>')
+    assert '''<div style="float: left;">
+<p><strong>blah</strong></p>
+</div>''' in r, r
+
 @with_setup(setUp)
 def test_markdown():
     'Just a test to get coverage in our markdown extension'