From c33ffe7dcd587b6f174d9f40049f43e628926b91 Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Thu, 6 Mar 2008 19:03:14 +0000 Subject: Moved line-endings cleanup from transform to convert method so it runs prior to textPreprocessors. Raw HTML with CRLF line endings now works properly. Also added a test. Fixes [1908691]. --- markdown.py | 13 ++++++------- tests/misc/CRLF_line_ends.html | 5 +++++ tests/misc/CRLF_line_ends.txt | 5 +++++ 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 tests/misc/CRLF_line_ends.html create mode 100644 tests/misc/CRLF_line_ends.txt diff --git a/markdown.py b/markdown.py index 97038ba..3dc8f00 100644 --- a/markdown.py +++ b/markdown.py @@ -1282,16 +1282,10 @@ class Markdown: self.top_element.setAttribute('class', 'markdown') self.doc.appendChild(self.top_element) - # Fixup the source text - text = self.source - text = text.replace("\r\n", "\n").replace("\r", "\n") - text += "\n\n" - text = text.expandtabs(TAB_LENGTH) - # Split into lines and run the preprocessors that will work with # self.lines - self.lines = text.split("\n") + self.lines = self.source.split("\n") # Run the pre-processors on the lines for prep in self.preprocessors : @@ -1727,6 +1721,11 @@ class Markdown: message(CRITICAL, 'UnicodeDecodeError: Markdown only accepts unicode or ascii input.') return u"" + # Fixup the source text + self.source = self.source.replace("\r\n", "\n").replace("\r", "\n") + self.source += "\n\n" + self.source = self.source.expandtabs(TAB_LENGTH) + for pp in self.textPreprocessors: self.source = pp.run(self.source) diff --git a/tests/misc/CRLF_line_ends.html b/tests/misc/CRLF_line_ends.html new file mode 100644 index 0000000..8e6849f --- /dev/null +++ b/tests/misc/CRLF_line_ends.html @@ -0,0 +1,5 @@ +

foo +

+
+bar +
\ No newline at end of file diff --git a/tests/misc/CRLF_line_ends.txt b/tests/misc/CRLF_line_ends.txt new file mode 100644 index 0000000..7d5e324 --- /dev/null +++ b/tests/misc/CRLF_line_ends.txt @@ -0,0 +1,5 @@ +foo + +
+bar +
-- cgit v1.2.3