From 4f8937810b1484a7bcbaf1d45df79433725e20a2 Mon Sep 17 00:00:00 2001 From: AlexVonB Date: Tue, 29 Dec 2020 10:28:50 +0100 Subject: [PATCH] dont replace newlines and tabs with spaces this should fix #17, as all leading new lines were replaced with a single space, which in turn was rendered before the # of a headline --- markdownify/__init__.py | 2 +- tests/test_basic.py | 2 +- tests/test_conversions.py | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 2cd8fc8..8ca1904 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -5,7 +5,7 @@ import six convert_heading_re = re.compile(r'convert_h(\d+)') line_beginning_re = re.compile(r'^', re.MULTILINE) -whitespace_re = re.compile(r'[\r\n\s\t ]+') +whitespace_re = re.compile(r'[\t ]+') html_heading_re = re.compile(r'h[1-6]') diff --git a/tests/test_basic.py b/tests/test_basic.py index 78775b6..bf25ee0 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -10,4 +10,4 @@ def test_soup(): def test_whitespace(): - assert md(' a b \n\n c ') == ' a b c ' + assert md(' a b \t\t c ') == ' a b c ' diff --git a/tests/test_conversions.py b/tests/test_conversions.py index f5fc1c2..657c016 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -106,6 +106,10 @@ def test_hn(): assert md('

Hello

') == '### Hello\n\n' assert md('
Hello
') == '###### Hello\n\n' +def test_hn_chained(): + assert md('

First

\n

Second

\n

Third

', heading_style=ATX) == '# First\n\n\n## Second\n\n\n### Third\n\n' + assert md('X

First

', heading_style=ATX) == 'X# First\n\n' + def test_hn_nested_tag_heading_style(): assert md('

A

P

C

', heading_style=ATX_CLOSED) == '# A P C #\n\n'