aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--markdown/extensions/fenced_code.py2
-rw-r--r--markdown/inlinepatterns.py2
-rw-r--r--markdown/postprocessors.py7
-rw-r--r--markdown/preprocessors.py3
-rw-r--r--tests/extensions/fenced_code.html32
-rw-r--r--tests/extensions/fenced_code.txt34
-rw-r--r--tests/extensions/github_flavored.html32
-rw-r--r--tests/extensions/github_flavored.txt34
-rw-r--r--tests/extensions/test.cfg6
-rw-r--r--tests/html4_safe/html_then_blockquote.html6
-rw-r--r--tests/html4_safe/html_then_blockquote.txt6
-rw-r--r--tests/html4_safe/link.html1
-rw-r--r--tests/html4_safe/link.txt1
-rw-r--r--tests/html4_safe/test.cfg3
-rw-r--r--tests/safe_mode/inline-html-simple.html11
-rw-r--r--tests/safe_mode/script_tags.html26
17 files changed, 182 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
index ebf5e84..c57cc74 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.DS*
*.pyc
*.bak
*.swp
@@ -8,4 +9,4 @@ tmp/*
MANIFEST
.venv
*~
-#*
+*#*
diff --git a/markdown/extensions/fenced_code.py b/markdown/extensions/fenced_code.py
index 0534251..95fe3b4 100644
--- a/markdown/extensions/fenced_code.py
+++ b/markdown/extensions/fenced_code.py
@@ -81,7 +81,7 @@ from markdown.extensions.codehilite import CodeHilite, CodeHiliteExtension
# Global vars
FENCED_BLOCK_RE = re.compile( \
- r'(?P<fence>^(?:~{3,}|`{3,}))[ ]*(\{?\.(?P<lang>[a-zA-Z0-9_-]*)\}?)?[ ]*\n(?P<code>.*?)(?P=fence)[ ]*$',
+ r'(?P<fence>^(?:~{3,}|`{3,}))[ ]*(\{?\.?(?P<lang>[a-zA-Z0-9_-]*)\}?)?[ ]*\n(?P<code>.*?)(?<=\n)(?P=fence)[ ]*$',
re.MULTILINE|re.DOTALL
)
CODE_WRAP = '<pre><code%s>%s</code></pre>'
diff --git a/markdown/inlinepatterns.py b/markdown/inlinepatterns.py
index 51b06d9..1829348 100644
--- a/markdown/inlinepatterns.py
+++ b/markdown/inlinepatterns.py
@@ -322,7 +322,7 @@ class LinkPattern(Pattern):
return ''
locless_schemes = ['', 'mailto', 'news']
- if netloc == '' or scheme not in locless_schemes:
+ if netloc == '' and scheme not in locless_schemes:
# This fails regardless of anything else.
# Return immediately to save additional proccessing
return ''
diff --git a/markdown/postprocessors.py b/markdown/postprocessors.py
index b21a569..962728b 100644
--- a/markdown/postprocessors.py
+++ b/markdown/postprocessors.py
@@ -49,7 +49,6 @@ class RawHtmlPostprocessor(Postprocessor):
""" Iterate over html stash and restore "safe" html. """
for i in range(self.markdown.htmlStash.html_counter):
html, safe = self.markdown.htmlStash.rawHtmlBlocks[i]
- html = self.unescape(html)
if self.markdown.safeMode and not safe:
if str(self.markdown.safeMode).lower() == 'escape':
html = self.escape(html)
@@ -61,6 +60,7 @@ class RawHtmlPostprocessor(Postprocessor):
text = text.replace("<p>%s</p>" %
(self.markdown.htmlStash.get_placeholder(i)),
html + "\n")
+ html = self.unescape(html)
text = text.replace(self.markdown.htmlStash.get_placeholder(i),
html)
return text
@@ -69,7 +69,10 @@ class RawHtmlPostprocessor(Postprocessor):
""" Unescape any markdown escaped text within inline html. """
for k, v in self.markdown.treeprocessors['inline'].stashed_nodes.items():
ph = util.INLINE_PLACEHOLDER % k
- html = html.replace(ph, '\%s' % v)
+ try:
+ html = html.replace(ph, '%s' % util.etree.tostring(v))
+ except:
+ html = html.replace(ph, '\%s' % v)
return html
def escape(self, html):
diff --git a/markdown/preprocessors.py b/markdown/preprocessors.py
index 0094d7b..c0f0034 100644
--- a/markdown/preprocessors.py
+++ b/markdown/preprocessors.py
@@ -14,7 +14,8 @@ import odict
def build_preprocessors(md_instance, **kwargs):
""" Build the default set of preprocessors used by Markdown. """
preprocessors = odict.OrderedDict()
- preprocessors["html_block"] = HtmlBlockPreprocessor(md_instance)
+ if md_instance.safeMode != 'escape':
+ preprocessors["html_block"] = HtmlBlockPreprocessor(md_instance)
preprocessors["reference"] = ReferencePreprocessor(md_instance)
return preprocessors
diff --git a/tests/extensions/fenced_code.html b/tests/extensions/fenced_code.html
new file mode 100644
index 0000000..7b86e79
--- /dev/null
+++ b/tests/extensions/fenced_code.html
@@ -0,0 +1,32 @@
+<p>index 0000000..6e956a9</p>
+<pre><code>--- /dev/null
++++ b/test/data/stripped_text/mike-30-lili
+@@ -0,0 +1,27 @@
++Summary:
++ drift_mod.py | 1 +
++ 1 files changed, 1 insertions(+), 0 deletions(-)
++
++commit da4bfb04debdd994683740878d09988b2641513d
++Author: Mike Dirolf &lt;mike@dirolf.com&gt;
++Date: Tue Jan 17 13:42:28 2012 -0500
++
++```
++minor: just wanted to push something.
++```
++
++diff --git a/drift_mod.py b/drift_mod.py
++index 34dfba6..8a88a69 100644
++
++```
++--- a/drift_mod.py
+++++ b/drift_mod.py
++@@ -281,6 +281,7 @@ CONTEXT_DIFF_LINE_PATTERN = re.compile(r'^('
++ '|\+ .*'
++ '|- .*'
++ ')$')
+++
++ def wrap_context_diffs(message_text):
++ return _wrap_diff(CONTEXT_DIFF_HEADER_PATTERN,
++ CONTEXT_DIFF_LINE_PATTERN,
++```
+</code></pre> \ No newline at end of file
diff --git a/tests/extensions/fenced_code.txt b/tests/extensions/fenced_code.txt
new file mode 100644
index 0000000..73c0337
--- /dev/null
+++ b/tests/extensions/fenced_code.txt
@@ -0,0 +1,34 @@
+index 0000000..6e956a9
+
+```
+--- /dev/null
++++ b/test/data/stripped_text/mike-30-lili
+@@ -0,0 +1,27 @@
++Summary:
++ drift_mod.py | 1 +
++ 1 files changed, 1 insertions(+), 0 deletions(-)
++
++commit da4bfb04debdd994683740878d09988b2641513d
++Author: Mike Dirolf <mike@dirolf.com>
++Date: Tue Jan 17 13:42:28 2012 -0500
++
++```
++minor: just wanted to push something.
++```
++
++diff --git a/drift_mod.py b/drift_mod.py
++index 34dfba6..8a88a69 100644
++
++```
++--- a/drift_mod.py
+++++ b/drift_mod.py
++@@ -281,6 +281,7 @@ CONTEXT_DIFF_LINE_PATTERN = re.compile(r'^('
++ '|\+ .*'
++ '|- .*'
++ ')$')
+++
++ def wrap_context_diffs(message_text):
++ return _wrap_diff(CONTEXT_DIFF_HEADER_PATTERN,
++ CONTEXT_DIFF_LINE_PATTERN,
++```
+```
diff --git a/tests/extensions/github_flavored.html b/tests/extensions/github_flavored.html
new file mode 100644
index 0000000..60e16b1
--- /dev/null
+++ b/tests/extensions/github_flavored.html
@@ -0,0 +1,32 @@
+<p>index 0000000..6e956a9</p>
+<div class="codehilite"><pre><span class="gd">--- /dev/null</span>
+<span class="gi">+++ b/test/data/stripped_text/mike-30-lili</span>
+<span class="gu">@@ -0,0 +1,27 @@</span>
+<span class="gi">+Summary:</span>
+<span class="gi">+ drift_mod.py | 1 +</span>
+<span class="gi">+ 1 files changed, 1 insertions(+), 0 deletions(-)</span>
+<span class="gi">+</span>
+<span class="gi">+commit da4bfb04debdd994683740878d09988b2641513d</span>
+<span class="gi">+Author: Mike Dirolf &lt;mike@dirolf.com&gt;</span>
+<span class="gi">+Date: Tue Jan 17 13:42:28 2012 -0500</span>
+<span class="gi">+</span>
+<span class="gi">+```</span>
+<span class="gi">+minor: just wanted to push something.</span>
+<span class="gi">+```</span>
+<span class="gi">+</span>
+<span class="gi">+diff --git a/drift_mod.py b/drift_mod.py</span>
+<span class="gi">+index 34dfba6..8a88a69 100644</span>
+<span class="gi">+</span>
+<span class="gi">+```</span>
+<span class="gi">+--- a/drift_mod.py</span>
+<span class="gi">++++ b/drift_mod.py</span>
+<span class="gi">+@@ -281,6 +281,7 @@ CONTEXT_DIFF_LINE_PATTERN = re.compile(r&#39;^(&#39;</span>
+<span class="gi">+ &#39;|\+ .*&#39;</span>
+<span class="gi">+ &#39;|- .*&#39;</span>
+<span class="gi">+ &#39;)$&#39;)</span>
+<span class="gi">++</span>
+<span class="gi">+ def wrap_context_diffs(message_text):</span>
+<span class="gi">+ return _wrap_diff(CONTEXT_DIFF_HEADER_PATTERN,</span>
+<span class="gi">+ CONTEXT_DIFF_LINE_PATTERN,</span>
+<span class="gi">+```</span>
+</pre></div> \ No newline at end of file
diff --git a/tests/extensions/github_flavored.txt b/tests/extensions/github_flavored.txt
new file mode 100644
index 0000000..d0737bd
--- /dev/null
+++ b/tests/extensions/github_flavored.txt
@@ -0,0 +1,34 @@
+index 0000000..6e956a9
+
+```diff
+--- /dev/null
++++ b/test/data/stripped_text/mike-30-lili
+@@ -0,0 +1,27 @@
++Summary:
++ drift_mod.py | 1 +
++ 1 files changed, 1 insertions(+), 0 deletions(-)
++
++commit da4bfb04debdd994683740878d09988b2641513d
++Author: Mike Dirolf <mike@dirolf.com>
++Date: Tue Jan 17 13:42:28 2012 -0500
++
++```
++minor: just wanted to push something.
++```
++
++diff --git a/drift_mod.py b/drift_mod.py
++index 34dfba6..8a88a69 100644
++
++```
++--- a/drift_mod.py
+++++ b/drift_mod.py
++@@ -281,6 +281,7 @@ CONTEXT_DIFF_LINE_PATTERN = re.compile(r'^('
++ '|\+ .*'
++ '|- .*'
++ ')$')
+++
++ def wrap_context_diffs(message_text):
++ return _wrap_diff(CONTEXT_DIFF_HEADER_PATTERN,
++ CONTEXT_DIFF_LINE_PATTERN,
++```
+```
diff --git a/tests/extensions/test.cfg b/tests/extensions/test.cfg
index c25bdfb..ebe9a8f 100644
--- a/tests/extensions/test.cfg
+++ b/tests/extensions/test.cfg
@@ -20,3 +20,9 @@ extensions=toc
[wikilinks]
extensions=wikilinks
+
+[fenced_code]
+extensions=fenced_code
+
+[github_flavored]
+extensions=codehilite,fenced_code
diff --git a/tests/html4_safe/html_then_blockquote.html b/tests/html4_safe/html_then_blockquote.html
new file mode 100644
index 0000000..5833cd4
--- /dev/null
+++ b/tests/html4_safe/html_then_blockquote.html
@@ -0,0 +1,6 @@
+<p>to:</p>
+<p>&lt;td /&gt;&lt;td style=&quot;text-align: center; white-space: nowrap;&quot;&gt;&lt;br /&gt;</p>
+<blockquote>
+<p>3) You don't need to alter all localization files.
+ Adding the new labels to the en_US files will do it.</p>
+</blockquote> \ No newline at end of file
diff --git a/tests/html4_safe/html_then_blockquote.txt b/tests/html4_safe/html_then_blockquote.txt
new file mode 100644
index 0000000..544df67
--- /dev/null
+++ b/tests/html4_safe/html_then_blockquote.txt
@@ -0,0 +1,6 @@
+to:
+
+<td /><td style="text-align: center; white-space: nowrap;"><br />
+
+> 3) You don't need to alter all localization files.
+> Adding the new labels to the en_US files will do it.
diff --git a/tests/html4_safe/link.html b/tests/html4_safe/link.html
new file mode 100644
index 0000000..642f4be
--- /dev/null
+++ b/tests/html4_safe/link.html
@@ -0,0 +1 @@
+<p>&lt;here <a href="http://gmail.com">gmail.com</a> is a link&gt;</p> \ No newline at end of file
diff --git a/tests/html4_safe/link.txt b/tests/html4_safe/link.txt
new file mode 100644
index 0000000..28331a7
--- /dev/null
+++ b/tests/html4_safe/link.txt
@@ -0,0 +1 @@
+<here [gmail.com](http://gmail.com) is a link>
diff --git a/tests/html4_safe/test.cfg b/tests/html4_safe/test.cfg
new file mode 100644
index 0000000..66f7bf0
--- /dev/null
+++ b/tests/html4_safe/test.cfg
@@ -0,0 +1,3 @@
+[DEFAULT]
+output_format=html4
+safe_mode=escape
diff --git a/tests/safe_mode/inline-html-simple.html b/tests/safe_mode/inline-html-simple.html
index ad19a77..aca9af0 100644
--- a/tests/safe_mode/inline-html-simple.html
+++ b/tests/safe_mode/inline-html-simple.html
@@ -29,7 +29,8 @@ Blah
<pre><code>&lt;!-- Comment --&gt;
</code></pre>
<p>Just plain comment, with trailing spaces on the line:</p>
-<p>&lt;!-- foo --&gt;</p>
+<p>&lt;!-- foo --&gt; <br />
+</p>
<p>Code:</p>
<pre><code>&lt;hr /&gt;
</code></pre>
@@ -37,9 +38,11 @@ Blah
<p>&lt;hr&gt;</p>
<p>&lt;hr/&gt;</p>
<p>&lt;hr /&gt;</p>
-<p>&lt;hr&gt;</p>
-<p>&lt;hr/&gt;</p>
-<p>&lt;hr /&gt;</p>
+<p>&lt;hr&gt; <br />
+</p>
+<p>&lt;hr/&gt;<br />
+</p>
+<p>&lt;hr /&gt; </p>
<p>&lt;hr class=&quot;foo&quot; id=&quot;bar&quot; /&gt;</p>
<p>&lt;hr class=&quot;foo&quot; id=&quot;bar&quot;/&gt;</p>
<p>&lt;hr class=&quot;foo&quot; id=&quot;bar&quot; &gt;</p> \ No newline at end of file
diff --git a/tests/safe_mode/script_tags.html b/tests/safe_mode/script_tags.html
index df63ffc..f3b059d 100644
--- a/tests/safe_mode/script_tags.html
+++ b/tests/safe_mode/script_tags.html
@@ -1,13 +1,11 @@
<p>This should be stripped/escaped in safe_mode.</p>
<p>&lt;script&gt;
-alert(&quot;Hello world!&quot;)
+alert("Hello world!")
&lt;/script&gt;</p>
<p>With blank lines.</p>
-<p>&lt;script&gt;
-
-alert(&quot;Hello world!&quot;)
-
-&lt;/script&gt;</p>
+<p>&lt;script&gt;</p>
+<p>alert("Hello world!")</p>
+<p>&lt;/script&gt;</p>
<p>Now with some weirdness</p>
<p><code>&lt;script &lt;!--
alert("Hello world!")
@@ -15,14 +13,8 @@ alert("Hello world!")
<p>Try another way.</p>
<p>&lt;script &lt;!--
alert(&quot;Hello world!&quot;)
-&lt;/script &lt;&gt;
-
-This time with blank lines.
-
-&lt;script &lt;!--
-
-alert(&quot;Hello world!&quot;)
-
-&lt;/script &lt;&gt;
-
-</p> \ No newline at end of file
+&lt;/script &lt;&gt;</p>
+<p>This time with blank lines.</p>
+<p>&lt;script &lt;!--</p>
+<p>alert("Hello world!")</p>
+<p>&lt;/script &lt;&gt;</p> \ No newline at end of file