From 1b96d38c20967c67b3bb4e0fcf007615104d731f Mon Sep 17 00:00:00 2001 From: Justin Mayer Date: Mon, 13 Apr 2026 19:52:15 +0200 Subject: [PATCH] test: Strip ToC divs & backref anchors from summary --- pelican/tests/test_contents.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pelican/tests/test_contents.py b/pelican/tests/test_contents.py index 4b1effa2..4e48e594 100644 --- a/pelican/tests/test_contents.py +++ b/pelican/tests/test_contents.py @@ -172,6 +172,28 @@ class TestPage(TestBase): ) self.assertIn("test_marker", page.summary) + def test_summary_strips_toc_elements(self): + """Auto-generated summary should strip TOC divs and toc-backref anchors.""" + page_kwargs = self._copy_page_kwargs() + settings = get_settings() + page_kwargs["settings"] = settings + del page_kwargs["metadata"]["summary"] + toc_content = ( + '
' + "

Table of contents

" + '' + "
" + '

My Section

' + "

First paragraph of real content.

" + ) + page_kwargs["content"] = toc_content + settings["SUMMARY_MAX_LENGTH"] = None + page = Page(**page_kwargs) + self.assertNotIn('
My Section", page.summary) + self.assertIn("

First paragraph of real content.

", page.summary) + def test_summary_get_summary_warning(self): """calling ._get_summary() should issue a warning""" page_kwargs = self._copy_page_kwargs()