Skip to content

Commit f33ccd7

Browse files
authored
Fix newline start in header tags (#89)
* Fix newline start in header tags
1 parent a2f8267 commit f33ccd7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

markdownify/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def convert_hn(self, n, el, text, convert_as_inline):
265265
return text
266266

267267
style = self.options['heading_style'].lower()
268-
text = text.rstrip()
268+
text = text.strip()
269269
if style == UNDERLINED and n <= 2:
270270
line = '=' if n == 1 else '-'
271271
return self.underline(text, line)

tests/test_conversions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ def test_em():
9090
inline_tests('em', '*')
9191

9292

93+
def test_header_with_space():
94+
assert md('<h3>\n\nHello</h3>') == '### Hello\n\n'
95+
assert md('<h4>\n\nHello</h4>') == '#### Hello\n\n'
96+
assert md('<h5>\n\nHello</h5>') == '##### Hello\n\n'
97+
assert md('<h5>\n\nHello\n\n</h5>') == '##### Hello\n\n'
98+
assert md('<h5>\n\nHello \n\n</h5>') == '##### Hello\n\n'
99+
100+
93101
def test_h1():
94102
assert md('<h1>Hello</h1>') == 'Hello\n=====\n\n'
95103

0 commit comments

Comments
 (0)