Skip to content

Commit

Permalink
Fixed Ticket 13. Raw block-level html are no longer being inserted in…
Browse files Browse the repository at this point in the history
…to <p> tags.

Also edited numerious tests that were expecting wrong output - they now expect
correct output. Note that a few **still fail** because the output before moving
to ELementTree wasn't correct either. So I set the expected output to what I
think it should be so we don't forget about it later.

I should also note that the 'safe-mode' tests are failing. However, I believe
the current expected output is correct as it is valid html. Interestingly,
these tests passed prior to this fix. We'll need to special case safe-mode here.
  • Loading branch information
Waylan Limberg committed Aug 22, 2008
1 parent 0efd44b commit a5cc42b
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 95 deletions.
2 changes: 1 addition & 1 deletion markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ def run(self, text):
else:
html = HTML_REMOVED_TEXT

text = text.replace("<p>%s\n</p>" % (HTML_PLACEHOLDER % i),
text = text.replace("<p>%s</p>" % (HTML_PLACEHOLDER % i),
html + "\n")
text = text.replace(HTML_PLACEHOLDER % i, html)
return text
Expand Down
7 changes: 4 additions & 3 deletions tests/markdown-test/inline-html-advanced.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<p>Simple block on one line:</p>
<p><div>foo</div></p>
<div>foo</div>

<p>And nested without indentation:</p>
<p><div>
<div>
<div>
<div>
foo
</div>
</div>
<div>bar</div>
</div></p>
</div>
11 changes: 7 additions & 4 deletions tests/markdown-test/inline-html-comments.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<p>Paragraph one.</p>
<p><!-- This is a simple comment --></p>
<p><!--
<!-- This is a simple comment -->

<!--
This is another comment.
--></p>
-->

<p>Paragraph two.</p>
<p><!-- one comment block -- -- with two comments --></p>
<!-- one comment block -- -- with two comments -->

<p>The end.</p>
55 changes: 34 additions & 21 deletions tests/markdown-test/inline-html-simple.html
Original file line number Diff line number Diff line change
@@ -1,53 +1,66 @@
<p>Here's a simple block:</p>
<p><div>
<div>
foo
</div></p>
</div>

<p>This should be a code block, though:</p>
<pre>
<code>&lt;div&gt;
<code>&lt;div&gt;
foo
&lt;/div&gt;
</code>
</pre>
<p>As should this:</p>
<pre>
<code>&lt;div&gt;foo&lt;/div&gt;
<code>&lt;div&gt;foo&lt;/div&gt;
</code>
</pre>
<p>Now, nested:</p>
<p><div>
<div>
<div>
<div>
foo
</div>
</div>
</div></p>
</div>

<p>This should just be an HTML comment:</p>
<p><!-- Comment --></p>
<!-- Comment -->

<p>Multiline:</p>
<p><!--
<!--
Blah
Blah
--></p>
-->

<p>Code block:</p>
<pre>
<code>&lt;!-- Comment --&gt;
<code>&lt;!-- Comment --&gt;
</code>
</pre>
<p>Just plain comment, with trailing spaces on the line:</p>
<p><!-- foo --></p>
<!-- foo -->

<p>Code:</p>
<pre>
<code>&lt;hr /&gt;
<code>&lt;hr /&gt;
</code>
</pre>
<p>Hr's:</p>
<p><hr></p>
<p><hr/></p>
<p><hr /></p>
<p><hr></p>
<p><hr/></p>
<p><hr /></p>
<p><hr class="foo" id="bar" /></p>
<p><hr class="foo" id="bar"/></p>
<p><hr class="foo" id="bar" ></p>
<hr>

<hr/>

<hr />

<hr>

<hr/>

<hr />

<hr class="foo" id="bar" />

<hr class="foo" id="bar"/>

<hr class="foo" id="bar" >
8 changes: 4 additions & 4 deletions tests/markdown-test/markdown-documentation-basics.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<h1>Markdown: Basics</h1>
<p><ul id="ProjectSubmenu">
<ul id="ProjectSubmenu">
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
<li><a class="selected" title="Markdown Basics">Basics</a></li>
<li><a href="/projects/markdown/syntax" title="Markdown Syntax Documentation">Syntax</a></li>
<li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
<li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
</ul></p>
</ul>

<h2>Getting the Gist of Markdown's Formatting Syntax</h2>
<p>This page offers a brief overview of what it's like to use Markdown.
The <a href="/projects/markdown/syntax" title="Markdown Syntax">syntax page</a> provides complete, detailed documentation for
Expand Down Expand Up @@ -294,5 +295,4 @@ <h3>Code</h3>
&amp;lt;/blockquote&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
</code>
</pre>

</pre>
65 changes: 42 additions & 23 deletions tests/markdown-test/markdown-syntax.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<h1>Markdown: Syntax</h1>
<p><ul id="ProjectSubmenu">
<ul id="ProjectSubmenu">
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
<li><a href="/projects/markdown/basics" title="Markdown Basics">Basics</a></li>
<li><a class="selected" title="Markdown Syntax Documentation">Syntax</a></li>
<li><a href="/projects/markdown/license" title="Pricing and License Information">License</a></li>
<li><a href="/projects/markdown/dingus" title="Online Markdown Web Form">Dingus</a></li>
</ul></p>
</ul>

<ul>
<li>
<a href="#overview">Overview</a>
Expand Down Expand Up @@ -77,8 +78,10 @@ <h1>Markdown: Syntax</h1>
<strong>Note:</strong> This document is itself written using Markdown; you
can <a href="/projects/markdown/syntax.text">see the source for it by adding '.text' to the URL</a>.</p>
<hr />
<p><h2 id="overview">Overview</h2></p>
<p><h3 id="philosophy">Philosophy</h3></p>
<h2 id="overview">Overview</h2>

<h3 id="philosophy">Philosophy</h3>

<p>Markdown is intended to be as easy-to-read and easy-to-write as is feasible.</p>
<p>Readability, however, is emphasized above all else. A Markdown-formatted
document should be publishable as-is, as plain text, without looking
Expand All @@ -93,7 +96,8 @@ <h1>Markdown: Syntax</h1>
look like *emphasis*. Markdown lists look like, well, lists. Even
blockquotes look like quoted passages of text, assuming you've ever
used email.</p>
<p><h3 id="html">Inline HTML</h3></p>
<h3 id="html">Inline HTML</h3>

<p>Markdown's syntax is intended for one purpose: to be used as a
format for <em>writing</em> for the web.</p>
<p>Markdown is not a replacement for HTML, or even close to it. Its
Expand Down Expand Up @@ -136,7 +140,8 @@ <h1>Markdown: Syntax</h1>
link or image syntax, go right ahead.</p>
<p>Unlike block-level HTML tags, Markdown syntax <em>is</em> processed within
span-level tags.</p>
<p><h3 id="autoescape">Automatic Escaping for Special Characters</h3></p>
<h3 id="autoescape">Automatic Escaping for Special Characters</h3>

<p>In HTML, there are two characters that demand special treatment: <code>&lt;</code>
and <code>&amp;</code>. Left angle brackets are used to start tags; ampersands are
used to denote HTML entities. If you want to use them as literal
Expand Down Expand Up @@ -194,8 +199,10 @@ <h1>Markdown: Syntax</h1>
terrible format for writing about HTML syntax, because every single <code>&lt;</code>
and <code>&amp;</code> in your example code needs to be escaped.)</p>
<hr />
<p><h2 id="block">Block Elements</h2></p>
<p><h3 id="p">Paragraphs and Line Breaks</h3></p>
<h2 id="block">Block Elements</h2>

<h3 id="p">Paragraphs and Line Breaks</h3>

<p>A paragraph is simply one or more consecutive lines of text, separated
by one or more blank lines. (A blank line is any line that looks like a
blank line -- a line containing nothing but spaces or tabs is considered
Expand All @@ -211,7 +218,8 @@ <h1>Markdown: Syntax</h1>
"every line break is a <code>&lt;br /&gt;</code>" rule wouldn't work for Markdown.
Markdown's email-style <a href="#blockquote">blockquoting</a> and multi-paragraph <a href="#list">list items</a>
work best -- and look better -- when you format them with hard breaks.</p>
<p><h3 id="header">Headers</h3></p>
<h3 id="header">Headers</h3>

<p>Markdown supports two styles of headers, <a href="http://docutils.sourceforge.net/mirror/setext.html">Setext</a> and <a href="http://www.aaronsw.com/2002/atx/">atx</a>.</p>
<p>Setext-style headers are "underlined" using equal signs (for first-level
headers) and dashes (for second-level headers). For example:</p>
Expand Down Expand Up @@ -247,7 +255,8 @@ <h1>Markdown: Syntax</h1>
### This is an H3 ######
</code>
</pre>
<p><h3 id="blockquote">Blockquotes</h3></p>
<h3 id="blockquote">Blockquotes</h3>

<p>Markdown uses email-style <code>&gt;</code> characters for blockquoting. If you're
familiar with quoting passages of text in an email message, then you
know how to create a blockquote in Markdown. It looks best if you hard
Expand Down Expand Up @@ -298,7 +307,8 @@ <h1>Markdown: Syntax</h1>
<p>Any decent text editor should make email-style quoting easy. For
example, with BBEdit, you can make a selection and choose Increase
Quote Level from the Text menu.</p>
<p><h3 id="list">Lists</h3></p>
<h3 id="list">Lists</h3>

<p>Markdown supports ordered (numbered) and unordered (bulleted) lists.</p>
<p>Unordered lists use asterisks, pluses, and hyphens -- interchangably
-- as list markers:</p>
Expand Down Expand Up @@ -469,7 +479,8 @@ <h1>Markdown: Syntax</h1>
<code>1986\. What a great season.
</code>
</pre>
<p><h3 id="precode">Code Blocks</h3></p>
<h3 id="precode">Code Blocks</h3>

<p>Pre-formatted code blocks are used for writing about programming or
markup source code. Rather than forming normal paragraphs, the lines
of a code block are interpreted literally. Markdown wraps a code block
Expand Down Expand Up @@ -534,7 +545,8 @@ <h1>Markdown: Syntax</h1>
<p>Regular Markdown syntax is not processed within code blocks. E.g.,
asterisks are just literal asterisks within a code block. This means
it's also easy to use Markdown to write about Markdown's own syntax.</p>
<p><h3 id="hr">Horizontal Rules</h3></p>
<h3 id="hr">Horizontal Rules</h3>

<p>You can produce a horizontal rule tag (<code>&lt;hr /&gt;</code>) by placing three or
more hyphens, asterisks, or underscores on a line by themselves. If you
wish, you may use spaces between the hyphens or asterisks. Each of the
Expand All @@ -554,8 +566,10 @@ <h1>Markdown: Syntax</h1>
</code>
</pre>
<hr />
<p><h2 id="span">Span Elements</h2></p>
<p><h3 id="link">Links</h3></p>
<h2 id="span">Span Elements</h2>

<h3 id="link">Links</h3>

<p>Markdown supports two style of links: <em>inline</em> and <em>reference</em>.</p>
<p>In both styles, the link text is delimited by [square brackets].</p>
<p>To create an inline link, use a set of regular parentheses immediately
Expand Down Expand Up @@ -707,7 +721,8 @@ <h1>Markdown: Syntax</h1>
allowing you to move the markup-related metadata out of the paragraph,
you can add links without interrupting the narrative flow of your
prose.</p>
<p><h3 id="em">Emphasis</h3></p>
<h3 id="em">Emphasis</h3>

<p>Markdown treats asterisks (<code>*</code>) and underscores (<code>_</code>) as indicators of
emphasis. Text wrapped with one <code>*</code> or <code>_</code> will be wrapped with an
HTML <code>&lt;em&gt;</code> tag; double <code>*</code>'s or <code>_</code>'s will be wrapped with an HTML
Expand Down Expand Up @@ -749,7 +764,8 @@ <h1>Markdown: Syntax</h1>
<code>\*this text is surrounded by literal asterisks\*
</code>
</pre>
<p><h3 id="code">Code</h3></p>
<h3 id="code">Code</h3>

<p>To indicate a span of code, wrap it with backtick quotes (<code>`</code>).
Unlike a pre-formatted code block, a code span indicates code within a
normal paragraph. For example:</p>
Expand Down Expand Up @@ -812,7 +828,8 @@ <h1>Markdown: Syntax</h1>
equivalent of &lt;code&gt;&amp;amp;mdash;&lt;/code&gt;.&lt;/p&gt;
</code>
</pre>
<p><h3 id="img">Images</h3></p>
<h3 id="img">Images</h3>

<p>Admittedly, it's fairly difficult to devise a "natural" syntax for
placing images into a plain text document format.</p>
<p>Markdown uses an image syntax that is intended to resemble the syntax
Expand Down Expand Up @@ -848,8 +865,10 @@ <h1>Markdown: Syntax</h1>
dimensions of an image; if this is important to you, you can simply
use regular HTML <code>&lt;img&gt;</code> tags.</p>
<hr />
<p><h2 id="misc">Miscellaneous</h2></p>
<p><h3 id="autolink">Automatic Links</h3></p>
<h2 id="misc">Miscellaneous</h2>

<h3 id="autolink">Automatic Links</h3>

<p>Markdown supports a shortcut style for creating "automatic" links for URLs and email addresses: simply surround the URL or email address with angle brackets. What this means is that if you want to show the actual text of a URL or email address, and also have it be a clickable link, you can do this:</p>
<pre>
<code>&lt;http://example.com/&gt;
Expand Down Expand Up @@ -881,7 +900,8 @@ <h1>Markdown: Syntax</h1>
most, address-harvesting bots, but it definitely won't fool all of
them. It's better than nothing, but an address published in this way
will probably eventually start receiving spam.)</p>
<p><h3 id="backslash">Backslash Escapes</h3></p>
<h3 id="backslash">Backslash Escapes</h3>

<p>Markdown allows you to use backslash escapes to generate literal
characters which would otherwise have special meaning in Markdown's
formatting syntax. For example, if you wanted to surround a word with
Expand All @@ -906,5 +926,4 @@ <h1>Markdown: Syntax</h1>
. dot
! exclamation mark
</code>
</pre>

</pre>
4 changes: 2 additions & 2 deletions tests/misc/CRLF_line_ends.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p>foo</p>
<p><div>
<div>
bar
</div></p>
</div>
5 changes: 3 additions & 2 deletions tests/misc/comments.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<p>X&lt;0</p>
<p>X&gt;0</p>
<p><!-- A comment --></p>
<p><div>as if</div></p>
<!-- A comment -->

<div>as if</div>
7 changes: 4 additions & 3 deletions tests/misc/div.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<p><div id="sidebar"></p>
<div id="sidebar">

<p>
<em>foo</em>
<em>foo</em>
</p>
<p></div></p>
</div>
10 changes: 6 additions & 4 deletions tests/misc/hash.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<p>a</p>
<p><pre>
<pre>
#!/usr/bin/python
hello</pre></p>
hello</pre>

<p>a</p>
<p><pre>
<pre>
!/usr/bin/python
hello</pre></p>
hello</pre>

<p>a</p>
6 changes: 2 additions & 4 deletions tests/misc/mismatched-tags.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<p><p>Some text</p><div>some more text</div>
<p>Some text</p><div>some more text</div>

and a bit more

</p>
<p>and a bit more</p>
Loading

0 comments on commit a5cc42b

Please sign in to comment.