Skip to content

Commit

Permalink
Fix newline start in header tags (#89)
Browse files Browse the repository at this point in the history
* Fix newline start in header tags
  • Loading branch information
5yato4ok authored Mar 26, 2024
1 parent a2f8267 commit f33ccd7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion markdownify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def convert_hn(self, n, el, text, convert_as_inline):
return text

style = self.options['heading_style'].lower()
text = text.rstrip()
text = text.strip()
if style == UNDERLINED and n <= 2:
line = '=' if n == 1 else '-'
return self.underline(text, line)
Expand Down
8 changes: 8 additions & 0 deletions tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ def test_em():
inline_tests('em', '*')


def test_header_with_space():
assert md('<h3>\n\nHello</h3>') == '### Hello\n\n'
assert md('<h4>\n\nHello</h4>') == '#### Hello\n\n'
assert md('<h5>\n\nHello</h5>') == '##### Hello\n\n'
assert md('<h5>\n\nHello\n\n</h5>') == '##### Hello\n\n'
assert md('<h5>\n\nHello \n\n</h5>') == '##### Hello\n\n'


def test_h1():
assert md('<h1>Hello</h1>') == 'Hello\n=====\n\n'

Expand Down

0 comments on commit f33ccd7

Please sign in to comment.