@@ -1132,6 +1132,69 @@ def test_post_summary_omits_reading_time_by_default(
11321132
11331133 assert "reading-time" not in html
11341134
1135+ def test_shift_headings_filter (self ) -> None :
1136+ """Test the shift_headings filter directly."""
1137+ html = "<h1>Title</h1><h2>Subtitle</h2><p>Text</p><h3>Small</h3>"
1138+
1139+ # Shift by 1
1140+ shifted = TemplateRenderer ._shift_headings (html , 1 )
1141+ assert "<h2>Title</h2>" in shifted
1142+ assert "<h3>Subtitle</h3>" in shifted
1143+ assert "<h4>Small</h4>" in shifted
1144+ assert "<p>Text</p>" in shifted
1145+
1146+ # Shift by 2
1147+ shifted = TemplateRenderer ._shift_headings (html , 2 )
1148+ assert "<h3>Title</h3>" in shifted
1149+ assert "<h4>Subtitle</h4>" in shifted
1150+ assert "<h5>Small</h5>" in shifted
1151+
1152+ # Clamping to h6
1153+ html_h6 = "<h6>Already small</h6>"
1154+ shifted = TemplateRenderer ._shift_headings (html_h6 , 1 )
1155+ assert "<h6>Already small</h6>" in shifted
1156+
1157+ # Shift by 0
1158+ assert TemplateRenderer ._shift_headings (html , 0 ) == html
1159+
1160+ # Negative shift (shift up)
1161+ html_h2 = "<h2>Title</h2>"
1162+ shifted = TemplateRenderer ._shift_headings (html_h2 , - 1 )
1163+ assert "<h1>Title</h1>" in shifted
1164+
1165+ # Clamping to h1
1166+ shifted = TemplateRenderer ._shift_headings (html_h2 , - 2 )
1167+ assert "<h1>Title</h1>" in shifted
1168+
1169+ def test_shift_headings_closing_tags (self ) -> None :
1170+ """Test that closing heading tags are also shifted."""
1171+ html = "<h2>Title</h2>"
1172+ shifted = TemplateRenderer ._shift_headings (html , 1 )
1173+ assert "<h3>Title</h3>" in shifted
1174+
1175+ def test_shift_headings_in_summary (self ) -> None :
1176+ """Test that headings are shifted when rendering a post summary."""
1177+ renderer = TemplateRenderer ()
1178+ post = Post (
1179+ path = Path ("test.md" ),
1180+ title = "Post Title" ,
1181+ content = "## Subheading" ,
1182+ html_content = "<h2>Subheading</h2>" ,
1183+ date = dt .datetime (2024 , 1 , 15 , 12 , 0 , 0 , tzinfo = dt .UTC ),
1184+ )
1185+
1186+ html = renderer .render_index (
1187+ posts = [post ],
1188+ page = 1 ,
1189+ total_pages = 1 ,
1190+ site_title = "Test Blog" ,
1191+ )
1192+
1193+ # Post title in index is h2
1194+ assert "<h2>" in html
1195+ # Subheading in content should be shifted to h3
1196+ assert "<h3>Subheading</h3>" in html
1197+
11351198 def test_listing_meta_tags_on_tag_page (self , sample_post : Post ) -> None :
11361199 """Test that tag pages include standard listing meta tags."""
11371200 renderer = TemplateRenderer ()
0 commit comments