Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVonB committed Nov 24, 2024
2 parents e935ce8 + 6258f5c commit 8f70e39
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions markdownify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def __getattr__(self, attr):
n = int(m.group(1))

def convert_tag(el, text, convert_as_inline):
return self.convert_hn(n, el, text, convert_as_inline)
return self._convert_hn(n, el, text, convert_as_inline)

convert_tag.__name__ = 'convert_h%s' % n
setattr(self, convert_tag.__name__, convert_tag)
Expand Down Expand Up @@ -311,10 +311,14 @@ def convert_code(self, el, text, convert_as_inline):

convert_kbd = convert_code

def convert_hn(self, n, el, text, convert_as_inline):
def _convert_hn(self, n, el, text, convert_as_inline):
""" Method name prefixed with _ to prevent <hn> to call this """
if convert_as_inline:
return text

# prevent MemoryErrors in case of very large n
n = max(1, min(6, n))

style = self.options['heading_style'].lower()
text = text.strip()
if style == UNDERLINED and n <= 2:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "markdownify"
version = "0.14.0"
version = "0.14.1"
authors = [{name = "Matthew Tretter", email = "[email protected]"}]
description = "Convert HTML to markdown."
readme = "README.rst"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def test_hn():
assert md('<h4>Hello</h4>') == '\n#### Hello\n\n'
assert md('<h5>Hello</h5>') == '\n##### Hello\n\n'
assert md('<h6>Hello</h6>') == '\n###### Hello\n\n'
assert md('<h10>Hello</h10>') == md('<h6>Hello</h6>')
assert md('<hn>Hello</hn>') == md('Hello')


def test_hn_chained():
Expand Down

0 comments on commit 8f70e39

Please sign in to comment.