From 2910c7df2604f9ac147e12e62e233029bae7c4be Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Wed, 25 Oct 2023 14:59:03 +0100 Subject: [PATCH] Fix admonitions without a trailing newline Fixes #578 --- ford/md_admonition.py | 3 ++- test/test_md_admonition.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ford/md_admonition.py b/ford/md_admonition.py index d233f5de..3e214274 100644 --- a/ford/md_admonition.py +++ b/ford/md_admonition.py @@ -226,7 +226,8 @@ def _process_admonitions( admonition.end_idx += 1 # Indent any intermediate lines - for idx in range(admonition.start_idx + 1, admonition.end_idx + 1): + end_line = min(len(lines), admonition.end_idx + 1) + for idx in range(admonition.start_idx + 1, end_line): if lines[idx] != "": lines[idx] = self.INDENT + lines[idx] diff --git a/test/test_md_admonition.py b/test/test_md_admonition.py index 56c0505d..69b42b0f 100644 --- a/test/test_md_admonition.py +++ b/test/test_md_admonition.py @@ -106,6 +106,24 @@ def test_explicit_end(): assert soup.div.text.strip() == "Note\nnote text\nsome blank lines\nbefore the end" +def test_explicit_end_no_newline(): + converted = convert( + """ + @note note text + some blank lines + + + before the end + @endnote""" + ) + + soup = BeautifulSoup(converted, features="html.parser") + assert len(soup) == 1 + assert sorted(soup.div["class"]) == ["alert", "alert-info"] + assert soup.find(class_="h4").text == "Note" + assert soup.div.text.strip() == "Note\nnote text\nsome blank lines\nbefore the end" + + def test_warning(): converted = convert( """