From 271950fb0da52b844574a2a3087e895d789e8ab6 Mon Sep 17 00:00:00 2001 From: Isaac Muse Date: Sun, 22 Dec 2024 18:52:21 -0700 Subject: [PATCH] More consistent newline handling in blocks extensions (#2553) --- docs/src/markdown/about/changelog.md | 1 + pymdownx/blocks/__init__.py | 4 ++-- pymdownx/snippets.py | 2 +- tests/test_extensions/test_blocks/test_html.py | 2 -- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/src/markdown/about/changelog.md b/docs/src/markdown/about/changelog.md index 561c042fa..2ceb2f136 100644 --- a/docs/src/markdown/about/changelog.md +++ b/docs/src/markdown/about/changelog.md @@ -8,6 +8,7 @@ - **FIX**: Snippets: Properly capture empty newline at end of file. - **FIX**: Snippets: Fix issue where when non sections of files are included, section labels are not stripped. - **FIX**: BetterEm: Fixes for complex cases. +- **FIX**: Blocks: More consistent handling of empty newlines in block processor extensions. ## 10.12 diff --git a/pymdownx/blocks/__init__.py b/pymdownx/blocks/__init__.py index 1ff961f56..f85f61ceb 100644 --- a/pymdownx/blocks/__init__.py +++ b/pymdownx/blocks/__init__.py @@ -372,10 +372,10 @@ def parse_blocks(self, blocks, entry): if is_atomic or not is_block: child = list(target)[-1] if len(target) else None text = target.text if child is None else child.tail - b = '\n\n'.join(unescape_markdown(self.md, [b], is_atomic)) + b = '\n\n'.join(unescape_markdown(self.md, [b], is_atomic)).strip('\n') if text: - text += '\n\n' + b + text += b if not b else '\n\n' + b else: text = b diff --git a/pymdownx/snippets.py b/pymdownx/snippets.py index 6cb175858..2ef750331 100644 --- a/pymdownx/snippets.py +++ b/pymdownx/snippets.py @@ -321,7 +321,7 @@ def parse_snippets(self, lines, file_name=None, is_url=False, is_section=False): st = int(span[0]) if span[0] else None start.append(st if st is None or st < 0 else max(0, st - 1)) en = int(span[1]) if len(span) > 1 and span[1] else None - end.append(en if en is None or en >= 0 else en) + end.append(en) elif m.group(3): section = m.group(3)[1:] diff --git a/tests/test_extensions/test_blocks/test_html.py b/tests/test_extensions/test_blocks/test_html.py index 4d62f65f2..f97af9ed0 100644 --- a/tests/test_extensions/test_blocks/test_html.py +++ b/tests/test_extensions/test_blocks/test_html.py @@ -251,8 +251,6 @@ def test_inline_and_md_in_html(self): **content** - - content ''', True