@@ -65,17 +65,10 @@ pub fn parse<'a>(input: &'a str, comment_string: &str) -> Vec<Token<'a>> {
6565 } else if let Some ( fence) = line_as_code_fence ( line) {
6666 toks. push ( Token :: FencedCodeBlock ( line) ) ;
6767 in_code_fence = Some ( fence) ;
68- } else if line. starts_with ( comment_string) {
69- let index = comment_string. len ( ) ;
70- let t = if & line[ index..] == " ------------------------ >8 ------------------------" {
68+ } else if let Some ( t) = line_as_comment_or_scissor ( line, comment_string) {
69+ if let Token :: Scissored ( _) = t {
7170 has_scissors = true ;
72- Token :: Scissored ( line)
73- } else if line[ index..] . starts_with ( " ignore-rest" ) {
74- has_scissors = true ;
75- Token :: Scissored ( line)
76- } else {
77- Token :: Comment ( line)
78- } ;
71+ }
7972 toks. push ( t) ;
8073 } else if is_line_blank_or_whitespace ( line) {
8174 if toks. last ( ) != Some ( & Token :: VerticalSpace ) {
@@ -179,6 +172,22 @@ fn extend_prose_buffer_with_line<'input>(
179172 None
180173}
181174
175+ fn line_as_comment_or_scissor < ' a > ( line : & ' a str , comment_string : & str ) -> Option < Token < ' a > > {
176+ line. strip_prefix ( comment_string) . map ( |comment_suffix| {
177+ match is_comment_suffix_scissor_marker ( comment_suffix) {
178+ true => Token :: Scissored ( line) ,
179+ false => Token :: Comment ( line) ,
180+ }
181+ } )
182+ }
183+
184+ fn is_comment_suffix_scissor_marker ( comment_suffix : & str ) -> bool {
185+ // https://git-scm.com/docs/git-commit#Documentation/git-commit.txt-scissors
186+ // https://github.com/jj-vcs/jj/blob/v0.31.0/cli/src/description_util.rs#L162
187+ comment_suffix == " ------------------------ >8 ------------------------"
188+ || comment_suffix. starts_with ( " ignore-rest" )
189+ }
190+
182191fn is_line_blank_or_whitespace ( line : & str ) -> bool {
183192 line. chars ( ) . all ( char:: is_whitespace)
184193}
0 commit comments