diff --git a/markdownify/__init__.py b/markdownify/__init__.py index cc3d153..c34e57e 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -315,6 +315,9 @@ def convert_hn(self, n, el, text, convert_as_inline): 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: diff --git a/tests/test_conversions.py b/tests/test_conversions.py index 0be1d0c..1c5f9c2 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -133,6 +133,7 @@ def test_hn(): assert md('