From 38f9ddeabd84aaeb18496e8056c6672263336f55 Mon Sep 17 00:00:00 2001 From: "Joey@macstudio" Date: Mon, 13 Jul 2026 03:54:49 +0800 Subject: [PATCH] Fix stripping one trailing pre newline --- markdownify/__init__.py | 2 +- tests/test_args.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/markdownify/__init__.py b/markdownify/__init__.py index 28cdaf6..27fb4ff 100644 --- a/markdownify/__init__.py +++ b/markdownify/__init__.py @@ -12,7 +12,7 @@ re_newline_whitespace = re.compile(r'[\t \r\n]*[\r\n][\t \r\n]*') re_html_heading = re.compile(r'h(\d+)') re_pre_lstrip1 = re.compile(r'^ *\n') -re_pre_rstrip1 = re.compile(r'\n *$') +re_pre_rstrip1 = re.compile(r'\n *\Z') re_pre_lstrip = re.compile(r'^[ \n]*\n') re_pre_rstrip = re.compile(r'[ \n]*$') diff --git a/tests/test_args.py b/tests/test_args.py index 838ef9d..1e996a0 100644 --- a/tests/test_args.py +++ b/tests/test_args.py @@ -38,6 +38,8 @@ def test_strip_pre(): assert markdownify("
  \n  \n  Hello  \n  \n  
") == "```\n Hello\n```" assert markdownify("
  \n  \n  Hello  \n  \n  
", strip_pre=STRIP) == "```\n Hello\n```" assert markdownify("
  \n  \n  Hello  \n  \n  
", strip_pre=STRIP_ONE) == "```\n \n Hello \n \n```" + assert markdownify("
\n\nHello\n\n
", strip_pre=STRIP_ONE) == "```\n\nHello\n\n```" + assert markdownify("
\n\nHello\n\n\n
", strip_pre=STRIP_ONE) == "```\n\nHello\n\n\n```" assert markdownify("
  \n  \n  Hello  \n  \n  
", strip_pre=None) == "```\n \n \n Hello \n \n \n```"