diff options
Diffstat (limited to 'markdown.py')
-rw-r--r-- | markdown.py | 31 |
1 files changed, 14 insertions, 17 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 |