diff options
-rw-r--r-- | markdown.py | 31 | ||||
-rw-r--r-- | tests/markdown-test/markdown-documentation-basics.html | 9 | ||||
-rw-r--r-- | tests/misc/headers.html | 8 | ||||
-rw-r--r-- | tests/misc/html.html | 7 | ||||
-rw-r--r-- | tests/misc/some-test.html | 13 | ||||
-rw-r--r-- | tests/misc/two-spaces.html | 13 |
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]*;)' # & +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 <em>are emphasized also</em>.</p> <p>Use two asterisks for <strong>strong emphasis</strong>. Or, if you prefer, <strong>use two underscores instead</strong>.</p> -</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:</p> &lt;p&gt;For example.&lt;/p&gt; &lt;/blockquote&gt; </code></pre> -</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>stuff</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 > 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 |