Merge branch 'develop'

This commit is contained in:
AlexVonB
2024-11-24 23:05:17 +01:00
3 changed files with 9 additions and 3 deletions

View File

@@ -213,7 +213,7 @@ class MarkdownConverter(object):
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)
@@ -311,10 +311,14 @@ class MarkdownConverter(object):
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:

View File

@@ -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 = "m@tthewwithanm.com"}]
description = "Convert HTML to markdown."
readme = "README.rst"

View File

@@ -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():