aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2007-10-11 01:02:30 +0000
committerWaylan Limberg <waylan@gmail.com>2007-10-11 01:02:30 +0000
commit503c9d416ef1ec7f6d820290c28d6ca1906cb8a0 (patch)
treee65341c20db9d22967528db55abeda9d19821c27
parent5d3f2f3020d6d15ef34dba5e195747c6f048d518 (diff)
downloadmarkdown-503c9d416ef1ec7f6d820290c28d6ca1906cb8a0.tar.gz
markdown-503c9d416ef1ec7f6d820290c28d6ca1906cb8a0.tar.bz2
markdown-503c9d416ef1ec7f6d820290c28d6ca1906cb8a0.zip
Replace LineBreaks preprocessor with an inlinePattern and update tests. Blank lines (" \n") and headers no longer get linebreaks and the two spaces are no longer preserved.
-rw-r--r--markdown.py31
-rw-r--r--tests/markdown-test/markdown-documentation-basics.html9
-rw-r--r--tests/misc/headers.html8
-rw-r--r--tests/misc/html.html7
-rw-r--r--tests/misc/some-test.html13
-rw-r--r--tests/misc/two-spaces.html13
6 files changed, 31 insertions, 50 deletions
diff --git a/markdown.py b/markdown.py
index fbaeb84..3042138 100644
--- a/markdown.py
+++ b/markdown.py
@@ -332,7 +332,7 @@ class Element :
buffer += childBuffer
- if self.nodeName in ['p', 'li', 'ul', 'ol',
+ if self.nodeName in ['p', 'br ', 'li', 'ul', 'ol',
'h1', 'h2', 'h3', 'h4'] :
buffer += "\n"
@@ -464,19 +464,6 @@ class LinePreprocessor (Preprocessor):
LINE_PREPROCESSOR = LinePreprocessor()
-class LineBreaksPreprocessor (Preprocessor):
- """Replaces double spaces at the end of the lines with <br/ >."""
-
- def run (self, lines) :
- for i in range(len(lines)) :
- if (lines[i].endswith(" ")
- and not RE.regExp['tabbed'].match(lines[i]) ):
- lines[i] += self.stash.store("<br />", safe=True)
- return lines
-
-LINE_BREAKS_PREPROCESSOR = LineBreaksPreprocessor()
-
-
class HtmlBlockPreprocessor (Preprocessor):
"""Removes html blocks from self.lines"""
@@ -678,6 +665,8 @@ AUTOMAIL_RE = r'<([^> \!]*@[^> ]*)>' # <me@example.com>
#HTML_RE = r'(\<[^\>]*\>)' # <...>
HTML_RE = r'(\<[a-zA-Z/][^\>]*\>)' # <...>
ENTITY_RE = r'(&[\#a-zA-Z0-9]*;)' # &amp;
+LINE_BREAK_RE = r' \n' # two spaces at end of line
+LINE_BREAK_2_RE = r' $' # two spaces at end of text
class Pattern:
@@ -706,6 +695,11 @@ class SimpleTagPattern (Pattern):
el.appendChild(doc.createTextNode(m.group(2)))
return el
+class SubstituteTagPattern (SimpleTagPattern):
+
+ def handleMatch (self, m, doc) :
+ return doc.createElement(self.tag)
+
class BacktickPattern (Pattern):
def __init__ (self, pattern):
@@ -856,6 +850,9 @@ EMPHASIS_PATTERN_2 = SimpleTagPattern(EMPHASIS_2_RE, 'em')
STRONG_EM_PATTERN = DoubleTagPattern(STRONG_EM_RE, 'strong,em')
STRONG_EM_PATTERN_2 = DoubleTagPattern(STRONG_EM_2_RE, 'strong,em')
+LINE_BREAK_PATTERN = SubstituteTagPattern(LINE_BREAK_RE, 'br ')
+LINE_BREAK_PATTERN_2 = SubstituteTagPattern(LINE_BREAK_2_RE, 'br ')
+
LINK_PATTERN = LinkPattern(LINK_RE)
LINK_ANGLED_PATTERN = LinkPattern(LINK_ANGLED_RE)
IMAGE_LINK_PATTERN = ImagePattern(IMAGE_LINK_RE)
@@ -1023,7 +1020,7 @@ class CorePatterns :
effort."""
patterns = {
- 'header': r'(#*)([^#]*)(#*)', # # A title
+ 'header': r'(#*)\s*([^#]*)(#*)', # # A title
'reference-def' : r'(\ ?\ ?\ ?)\[([^\]]*)\]:\s*([^ ]*)(.*)',
# [Google]: http://www.google.com/
'containsline': r'([-]*)$|^([=]*)', # -----, =====, etc.
@@ -1075,7 +1072,6 @@ class Markdown:
self.preprocessors = [ HEADER_PREPROCESSOR,
LINE_PREPROCESSOR,
- LINE_BREAKS_PREPROCESSOR,
# A footnote preprocessor will
# get inserted here
REFERENCE_PREPROCESSOR ]
@@ -1100,6 +1096,8 @@ class Markdown:
LINK_PATTERN,
AUTOLINK_PATTERN,
AUTOMAIL_PATTERN,
+ LINE_BREAK_PATTERN_2,
+ LINE_BREAK_PATTERN,
HTML_PATTERN,
ENTITY_PATTERN,
NOT_STRONG_PATTERN,
@@ -1158,7 +1156,6 @@ class Markdown:
HTML_BLOCK_PREPROCESSOR.stash = self.htmlStash
LINE_PREPROCESSOR.stash = self.htmlStash
- LINE_BREAKS_PREPROCESSOR.stash = self.htmlStash
REFERENCE_PREPROCESSOR.references = self.references
HTML_PATTERN.stash = self.htmlStash
ENTITY_PATTERN.stash = self.htmlStash
diff --git a/tests/markdown-test/markdown-documentation-basics.html b/tests/markdown-test/markdown-documentation-basics.html
index fdfc33b..1dafe24 100644
--- a/tests/markdown-test/markdown-documentation-basics.html
+++ b/tests/markdown-test/markdown-documentation-basics.html
@@ -1,5 +1,3 @@
-
-
<h1>Markdown: Basics</h1>
<ul id="ProjectSubmenu">
<li><a href="/projects/markdown/" title="Markdown Project Page">Main</a></li>
@@ -103,9 +101,7 @@ Some of these words &lt;em&gt;are emphasized also&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Use two asterisks for &lt;strong&gt;strong emphasis&lt;/strong&gt;.
Or, if you prefer, &lt;strong&gt;use two underscores instead&lt;/strong&gt;.&lt;/p&gt;
-</code></pre><p> <br />
-</p>
-
+</code></pre>
<h2>Lists</h2>
<p>Unordered (bulleted) lists use asterisks, pluses, and hyphens (<code>*</code>,
<code>+</code>, and <code>-</code>) as list markers. These three markers are
@@ -262,5 +258,4 @@ you've got to put paragraph tags in your blockquotes:&lt;/p&gt;
&amp;lt;p&amp;gt;For example.&amp;lt;/p&amp;gt;
&amp;lt;/blockquote&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
-</code></pre>
-
+</code></pre> \ No newline at end of file
diff --git a/tests/misc/headers.html b/tests/misc/headers.html
index 306eb65..61bc266 100644
--- a/tests/misc/headers.html
+++ b/tests/misc/headers.html
@@ -1,14 +1,10 @@
-
-
<h3>Hello world</h3>
<p>Line 2
Line 3
</p>
-<h1>[Markdown][5] <br /></h1>
+<h1>[Markdown][5]</h1>
<h1><a href="http://some.link.com/">Markdown</a></h1>
-<h1>[5]: http://foo.com/</h1>
-
-
+<h1>[5]: http://foo.com/</h1> \ No newline at end of file
diff --git a/tests/misc/html.html b/tests/misc/html.html
index 6db122a..1209112 100644
--- a/tests/misc/html.html
+++ b/tests/misc/html.html
@@ -1,13 +1,10 @@
-
<h1>Block level html</h1>
-<p>Some inline <b>stuff<b>. <br />
+<p>Some inline <b>stuff<b>.<br />
</p>
<p>Now some <arbitrary>arbitrary tags</arbitrary>.
</p>
<p>And of course <script>blah</script>.
</p>
<p><a href="script&gt;stuff&lt;/script">this <script>link</a>
-</p>
-
-
+</p> \ No newline at end of file
diff --git a/tests/misc/some-test.html b/tests/misc/some-test.html
index 9a6655e..646482e 100644
--- a/tests/misc/some-test.html
+++ b/tests/misc/some-test.html
@@ -1,4 +1,3 @@
-
<hr />
<ul>
@@ -66,12 +65,13 @@
<li><p>Python is
ok
Or not?
- <br />
- Here is a normal paragraph
</p>
</li>
-
+</ul>
+<p>Here is a normal paragraph
+</p>
+<ol>
<li><p>Another list
with a bunch of items
</p>
@@ -91,7 +91,7 @@
</ol>
</li>
-</ul>
+</ol>
<p>asdfasdfasd
</p>
<pre><code># This is a code example
@@ -101,5 +101,4 @@ Another code example
* Lists and similar stuff
&gt; Should be ignored
-</code></pre>
-
+</code></pre> \ No newline at end of file
diff --git a/tests/misc/two-spaces.html b/tests/misc/two-spaces.html
index 10f8483..e66fe43 100644
--- a/tests/misc/two-spaces.html
+++ b/tests/misc/two-spaces.html
@@ -1,9 +1,6 @@
-
-<p>This line has two spaces at the end <br />
- but this one has none
- but this line has three <br />
- and this is the second from last line
+<p>This line has two spaces at the end<br />
+but this one has none
+ but this line has three <br />
+and this is the second from last line
in this test message
-</p>
-
-
+</p> \ No newline at end of file