@@ -40,7 +40,7 @@ pub fn try_make_title_case(
4040 let start_index = toks. first ( ) . unwrap ( ) . span . start ;
4141 let relevant_text = toks. span ( ) . unwrap ( ) . get_content ( source) ;
4242
43- let mut word_likes = toks. iter_word_like_indices ( ) . enumerate ( ) . peekable ( ) ;
43+ let mut word_likes = toks. iter_word_like_indices ( ) . peekable ( ) ;
4444
4545 let mut output = None ;
4646 let mut previous_word_index = 0 ;
@@ -65,8 +65,15 @@ pub fn try_make_title_case(
6565 }
6666 } ;
6767
68- while let Some ( ( index, word_idx) ) = word_likes. next ( ) {
68+ let mut seen_alphabetic_word = false ;
69+
70+ while let Some ( word_idx) = word_likes. next ( ) {
6971 let word = & toks[ word_idx] ;
72+ let is_alphabetic_word = word
73+ . span
74+ . get_content ( source)
75+ . iter ( )
76+ . any ( |c| c. is_alphabetic ( ) ) ;
7077
7178 if let Some ( Some ( metadata) ) = word. kind . as_word ( )
7279 && metadata. is_proper_noun ( )
@@ -89,9 +96,10 @@ pub fn try_make_title_case(
8996 . iter ( )
9097 . any ( |tok| matches ! ( tok. kind, TokenKind :: Punctuation ( Punctuation :: Colon ) ) ) ;
9198
99+ let is_first_alphabetic_word = is_alphabetic_word && !seen_alphabetic_word;
92100 let should_capitalize = is_after_colon
93101 || should_capitalize_token ( word, source)
94- || index == 0
102+ || is_first_alphabetic_word
95103 || word_likes. peek ( ) . is_none ( ) ;
96104
97105 if should_capitalize {
@@ -109,6 +117,10 @@ pub fn try_make_title_case(
109117 }
110118 }
111119
120+ if is_alphabetic_word {
121+ seen_alphabetic_word = true ;
122+ }
123+
112124 previous_word_index = word_idx
113125 }
114126
0 commit comments