@@ -119,14 +119,13 @@ fn slugify_heading(text: &str) -> String {
119119 // Look for ](url) pattern
120120 if let Some ( close) = text[ i+1 ..] . find ( ']' ) {
121121 let close_abs = i + 1 + close;
122- if close_abs + 1 < len && bytes[ close_abs + 1 ] == b'(' {
123- if let Some ( paren_close) = text[ close_abs+2 ..] . find ( ')' ) {
122+ if close_abs + 1 < len && bytes[ close_abs + 1 ] == b'('
123+ && let Some ( paren_close) = text[ close_abs+2 ..] . find ( ')' ) {
124124 // Extract link text only
125125 cleaned. push_str ( & text[ i+1 ..close_abs] ) ;
126126 i = close_abs + 2 + paren_close + 1 ;
127127 continue ;
128128 }
129- }
130129 }
131130 i += 1 ;
132131 } else if bytes[ i] == b'*' || bytes[ i] == b'_' || bytes[ i] == b'`' || bytes[ i] == b'~' {
@@ -693,19 +692,18 @@ impl ConvertState {
693692 let configured_new_lines = new_line_config[ 0 ] ;
694693
695694 // Clean mode — single guard for all clean checks
696- if self . clean_flags != 0 {
697- if let Some ( id) = tag_id {
695+ if self . clean_flags != 0
696+ && let Some ( id) = tag_id {
698697 if id == TAG_A {
699698 // emptyLinks: skip href="#" or "javascript:"
700699 if self . clean_flags & CLEAN_EMPTY_LINKS != 0 {
701700 let node = & self . stack [ self . stack . len ( ) - 1 ] ;
702- if let Some ( href) = node. attributes . get ( "href" ) {
703- if href == "#" || href. starts_with ( "javascript:" ) {
701+ if let Some ( href) = node. attributes . get ( "href" )
702+ && ( href == "#" || href. starts_with ( "javascript:" ) ) {
704703 self . skip_current_link = true ;
705704 self . last_node_is_inline = is_inline;
706705 return ;
707706 }
708- }
709707 self . skip_current_link = false ;
710708 }
711709 // Record buffer position BEFORE write_output emits `[`
@@ -720,19 +718,16 @@ impl ConvertState {
720718 }
721719 }
722720 }
723- }
724721
725722 self . write_output ( true , is_inline, configured_new_lines, output. as_deref ( ) ) ;
726723
727724 // Clean: track heading start for slug collection
728- if self . clean_flags & CLEAN_FRAGMENTS != 0 {
729- if let Some ( id) = tag_id {
730- if ( TAG_H1 ..=TAG_H6 ) . contains ( & id) && self . depth_map [ TAG_A as usize ] == 0 {
725+ if self . clean_flags & CLEAN_FRAGMENTS != 0
726+ && let Some ( id) = tag_id
727+ && ( TAG_H1 ..=TAG_H6 ) . contains ( & id) && self . depth_map [ TAG_A as usize ] == 0 {
731728 self . in_heading = true ;
732729 self . heading_buffer_start = self . buffer . len ( ) ;
733730 }
734- }
735- }
736731 }
737732
738733 /// Emit markdown for exiting an element (node already popped from stack).
@@ -843,9 +838,9 @@ impl ConvertState {
843838 // selfLinkHeadings: ## [Title](#slug) → ## Title
844839 if self . clean_flags & CLEAN_SELF_LINK_HEADINGS != 0 {
845840 let in_heading = ( TAG_H1 ..=TAG_H6 ) . any ( |h| self . depth_map [ h as usize ] > 0 ) ;
846- if in_heading {
847- if let Some ( href) = node. attributes . get ( "href" ) {
848- if href. starts_with ( '#' ) && text_len > 0 {
841+ if in_heading
842+ && let Some ( href) = node. attributes . get ( "href" )
843+ && href. starts_with ( '#' ) && text_len > 0 {
849844 // Remove [ and keep text only — use truncate+copy without intermediate String
850845 let new_len = bracket_pos + text_len;
851846 // SAFETY: bracket_pos < text_start are within buffer bounds (guarded above).
@@ -860,13 +855,11 @@ impl ConvertState {
860855 self . last_node_is_inline = is_inline;
861856 return ;
862857 }
863- }
864- }
865858 }
866859
867860 // redundantLinks: [url](url) → url
868- if self . clean_flags & CLEAN_REDUNDANT_LINKS != 0 {
869- if let Some ( href) = node. attributes . get ( "href" ) {
861+ if self . clean_flags & CLEAN_REDUNDANT_LINKS != 0
862+ && let Some ( href) = node. attributes . get ( "href" ) {
870863 let resolved = Self :: resolve_url ( href, self . options . origin . as_deref ( ) , self . options . clean_urls ) ;
871864 if link_text == resolved. as_ref ( ) && text_len > 0 {
872865 // Remove [ and keep text only — use truncate+copy without intermediate String
@@ -883,22 +876,19 @@ impl ConvertState {
883876 return ;
884877 }
885878 }
886- }
887879 }
888880
889881 // Collect heading slug before writing exit output
890- if self . in_heading {
891- if let Some ( id) = tag_id {
892- if ( TAG_H1 ..=TAG_H6 ) . contains ( & id) {
882+ if self . in_heading
883+ && let Some ( id) = tag_id
884+ && ( TAG_H1 ..=TAG_H6 ) . contains ( & id) {
893885 let heading_text = & self . buffer [ self . heading_buffer_start ..] ;
894886 let slug = slugify_heading ( heading_text) ;
895887 if !slug. is_empty ( ) {
896888 self . heading_slugs . push ( slug) ;
897889 }
898890 self . in_heading = false ;
899891 }
900- }
901- }
902892
903893 // TAG_A exit: write ](url) directly to buffer — zero allocation
904894 if !has_override && tag_id == Some ( TAG_A ) && table_separator. is_none ( ) {
@@ -927,16 +917,14 @@ impl ConvertState {
927917 self . last_content_cache_len = self . buffer . len ( ) ; // will be recalculated
928918 }
929919 // Record fragment link position for deferred fixup
930- if self . clean_flags & CLEAN_FRAGMENTS != 0 {
931- if let Some ( href) = node. attributes . get ( "href" ) {
932- if href. starts_with ( '#' ) && href. len ( ) > 1 {
920+ if self . clean_flags & CLEAN_FRAGMENTS != 0
921+ && let Some ( href) = node. attributes . get ( "href" )
922+ && href. starts_with ( '#' ) && href. len ( ) > 1 {
933923 let mut bp = self . link_bracket_pos ;
934924 let buf = self . buffer . as_bytes ( ) ;
935925 while bp < buf. len ( ) && buf[ bp] != b'[' { bp += 1 ; }
936926 self . fragment_links . push ( ( bp, self . buffer . len ( ) ) ) ;
937927 }
938- }
939- }
940928 self . last_node_is_inline = is_inline;
941929 return ;
942930 }
@@ -951,17 +939,15 @@ impl ConvertState {
951939 self . write_output ( false , is_inline, configured_new_lines, effective) ;
952940
953941 // Record fragment link position for deferred fixup (no String alloc)
954- if self . clean_flags & CLEAN_FRAGMENTS != 0 && tag_id == Some ( TAG_A ) {
955- if let Some ( href) = node. attributes . get ( "href" ) {
956- if href. starts_with ( '#' ) && href. len ( ) > 1 {
942+ if self . clean_flags & CLEAN_FRAGMENTS != 0 && tag_id == Some ( TAG_A )
943+ && let Some ( href) = node. attributes . get ( "href" )
944+ && href. starts_with ( '#' ) && href. len ( ) > 1 {
957945 // Find actual [ position from recorded hint
958946 let mut bp = self . link_bracket_pos ;
959947 let buf = self . buffer . as_bytes ( ) ;
960948 while bp < buf. len ( ) && buf[ bp] != b'[' { bp += 1 ; }
961949 self . fragment_links . push ( ( bp, self . buffer . len ( ) ) ) ;
962950 }
963- }
964- }
965951 }
966952
967953 /// Emit markdown for a text node (no TextNode allocation).
@@ -1417,8 +1403,8 @@ impl ConvertState {
14171403 for _ in 0 ..new_lines { self . buffer . push ( '\n' ) ; }
14181404 }
14191405 } else {
1420- if let Some ( parent) = self . stack . last ( ) {
1421- if self . last_text_node_contains_whitespace
1406+ if let Some ( parent) = self . stack . last ( )
1407+ && self . last_text_node_contains_whitespace
14221408 && ( self . depth_map [ TAG_PRE as usize ] == 0 || parent. tag_id == Some ( TAG_PRE ) ) {
14231409 let h_is_inline = is_inline;
14241410 let collapses = parent. collapses_inner_white_space ;
@@ -1442,7 +1428,6 @@ impl ConvertState {
14421428 self . last_text_node_contains_whitespace = false ;
14431429 self . has_last_text_node = false ;
14441430 }
1445- }
14461431
14471432 if is_enter && !output_str. is_empty ( ) && last_char != 0 && self . needs_spacing ( last_char, output_str. as_bytes ( ) [ 0 ] ) {
14481433 self . buffer . push ( ' ' ) ;
@@ -1573,9 +1558,9 @@ impl ConvertState {
15731558 self . has_encoded_html_entity = false ;
15741559 }
15751560
1576- if self . has_tailwind {
1577- if let Some ( parent) = self . stack . last ( ) {
1578- if let Some ( tw) = & parent. tailwind {
1561+ if self . has_tailwind
1562+ && let Some ( parent) = self . stack . last ( )
1563+ && let Some ( tw) = & parent. tailwind {
15791564 if tw. hidden {
15801565 excludes_text_nodes = true ;
15811566 } else if !excludes_text_nodes {
@@ -1587,8 +1572,6 @@ impl ConvertState {
15871572 if modified { text = fix_redundant_delimiters ( & new_text) ; }
15881573 }
15891574 }
1590- }
1591- }
15921575
15931576 if !self . extraction_tracked . is_empty ( ) {
15941577 let current_depth = self . stack . len ( ) ;
@@ -1710,9 +1693,8 @@ impl ConvertState {
17101693 }
17111694
17121695 if self . has_filter {
1713- if let Some ( style) = tag. attributes . get ( "style" ) {
1714- if style. contains ( "absolute" ) || style. contains ( "fixed" ) { skip_node = true ; }
1715- }
1696+ if let Some ( style) = tag. attributes . get ( "style" )
1697+ && ( style. contains ( "absolute" ) || style. contains ( "fixed" ) ) { skip_node = true ; }
17161698 if !skip_node {
17171699 for ( _, parsed) in & self . filter_exclude_parsed {
17181700 if matches_selector ( & tag, parsed) { skip_node = true ; filter_excluded = true ; break ; }
@@ -1756,15 +1738,14 @@ impl ConvertState {
17561738 {
17571739 self . isolate_first_header_depth = Some ( self . depth ) ;
17581740 }
1759- if let Some ( header_depth) = self . isolate_first_header_depth {
1760- if !self . isolate_after_footer
1741+ if let Some ( header_depth) = self . isolate_first_header_depth
1742+ && !self . isolate_after_footer
17611743 && tag_id == Some ( TAG_FOOTER )
17621744 && self . depth . saturating_sub ( header_depth) <= 5
17631745 {
17641746 self . isolate_after_footer = true ;
17651747 skip_node = true ;
17661748 }
1767- }
17681749 if self . isolate_first_header_depth . is_none ( ) {
17691750 if tag_id != Some ( TAG_HEAD ) && self . depth_map [ TAG_HEAD as usize ] == 0 { skip_node = true ; }
17701751 } else if self . isolate_after_footer {
@@ -1819,8 +1800,8 @@ impl ConvertState {
18191800 self . stack . push ( tag) ;
18201801
18211802 // Extraction
1822- if !self . extraction_parsed_selectors . is_empty ( ) {
1823- if let Some ( element) = self . stack . last ( ) {
1803+ if !self . extraction_parsed_selectors . is_empty ( )
1804+ && let Some ( element) = self . stack . last ( ) {
18241805 let stack_depth = self . stack . len ( ) ;
18251806 for ( selector, parsed) in & self . extraction_parsed_selectors {
18261807 if matches_selector ( element, parsed) {
@@ -1835,7 +1816,6 @@ impl ConvertState {
18351816 }
18361817 }
18371818 }
1838- }
18391819
18401820 // Inline emit (no callback!)
18411821 if !skip_node {
@@ -1984,14 +1964,13 @@ impl ConvertState {
19841964 } ;
19851965 let tag_id = crate :: consts:: get_tag_id ( & tag_name) ;
19861966
1987- if let Some ( curr) = self . stack . last ( ) {
1988- if curr. is_non_nesting && curr. tag_id != tag_id {
1967+ if let Some ( curr) = self . stack . last ( )
1968+ && curr. is_non_nesting && curr. tag_id != tag_id {
19891969 return CloseTagResult {
19901970 complete : false , new_position : position,
19911971 remaining_start : position,
19921972 } ;
19931973 }
1994- }
19951974
19961975 if let Some ( top) = self . stack . last ( ) {
19971976 // Fast path: top of stack matches (well-formed HTML)
@@ -2056,8 +2035,8 @@ impl ConvertState {
20562035 yaml_out. push ( format ! ( "title: {}" , format_val( t) ) ) ;
20572036 }
20582037
2059- if let Some ( f) = f_opts {
2060- if let Some ( add) = & f. additional_fields {
2038+ if let Some ( f) = f_opts
2039+ && let Some ( add) = & f. additional_fields {
20612040 let mut sorted: Vec < _ > = add. iter ( ) . collect ( ) ;
20622041 sorted. sort_by ( |( a, _) , ( b, _) | a. cmp ( b) ) ;
20632042 for ( key, val) in sorted {
@@ -2066,7 +2045,6 @@ impl ConvertState {
20662045 }
20672046 }
20682047 }
2069- }
20702048
20712049 if !self . frontmatter_meta . is_empty ( ) {
20722050 yaml_out. push ( "meta:" . to_string ( ) ) ;
0 commit comments