@@ -278,11 +278,36 @@ fn matches_check(check: &WeightedCheck, readme_lower: &str, headings: &[String])
278278fn extract_normalized_headings ( readme_lower : & str ) -> Vec < String > {
279279 let mut headings = Vec :: new ( ) ;
280280 let mut fence: Option < FenceSpec > = None ;
281+ let mut front_matter_possible = true ;
282+ let mut in_front_matter = false ;
281283 let lines: Vec < & str > = readme_lower. lines ( ) . collect ( ) ;
282284 let mut index = 0usize ;
283285
284286 while index < lines. len ( ) {
285287 let trimmed = lines[ index] . trim_start ( ) ;
288+ let trimmed_both = lines[ index] . trim ( ) ;
289+
290+ if front_matter_possible && trimmed_both. is_empty ( ) {
291+ index += 1 ;
292+ continue ;
293+ }
294+
295+ if front_matter_possible {
296+ front_matter_possible = false ;
297+ if trimmed_both == "---" || trimmed_both == "+++" {
298+ in_front_matter = true ;
299+ index += 1 ;
300+ continue ;
301+ }
302+ }
303+
304+ if in_front_matter {
305+ if trimmed_both == "---" || trimmed_both == "+++" || trimmed_both == "..." {
306+ in_front_matter = false ;
307+ }
308+ index += 1 ;
309+ continue ;
310+ }
286311
287312 if let Some ( current_fence) = fence {
288313 if is_closing_fence ( trimmed, current_fence) {
@@ -568,4 +593,37 @@ License
568593 assert ! ( audit. missing_required. contains( & "Features" ) ) ;
569594 assert ! ( audit. missing_required. contains( & "Quick Start" ) ) ;
570595 }
596+
597+ #[ test]
598+ fn does_not_close_fence_with_shorter_length ( ) {
599+ let readme = "
600+ ````markdown
601+ ## Features
602+ ```
603+ ## Quick Start
604+ ````
605+ ## Architecture
606+ ## License
607+ " ;
608+
609+ let audit = audit_repo ( & example_repo ( ) , Some ( readme) , 70 , false ) ;
610+ assert ! ( audit. missing_required. contains( & "Features" ) ) ;
611+ assert ! ( audit. missing_required. contains( & "Quick Start" ) ) ;
612+ }
613+
614+ #[ test]
615+ fn ignores_yaml_front_matter_for_heading_detection ( ) {
616+ let readme = "
617+ ---
618+ title: Example project
619+ features: false
620+ ---
621+ ## Quick Start
622+ ## Architecture
623+ ## License
624+ " ;
625+
626+ let audit = audit_repo ( & example_repo ( ) , Some ( readme) , 70 , false ) ;
627+ assert ! ( audit. missing_required. contains( & "Features" ) ) ;
628+ }
571629}
0 commit comments