@@ -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}
@@ -260,7 +269,7 @@ fn is_line_trailer(line: &str) -> bool {
260269 }
261270}
262271
263- fn line_as_list_item ( line : & str ) -> Option < Token > {
272+ fn line_as_list_item ( line : & str ) -> Option < Token < ' _ > > {
264273 enum LiState {
265274 New ,
266275 IndentSp1 ,
@@ -349,7 +358,7 @@ fn line_as_list_item(line: &str) -> Option<Token> {
349358 } )
350359}
351360
352- fn line_as_code_fence ( line : & ' _ str ) -> Option < CodeFence > {
361+ fn line_as_code_fence ( line : & str ) -> Option < CodeFence < ' _ > > {
353362 enum FenceState {
354363 New ,
355364 IndentSp1 ,
@@ -407,7 +416,7 @@ fn line_as_code_fence(line: &'_ str) -> Option<CodeFence> {
407416 }
408417}
409418
410- fn line_as_line_block_quote ( line : & str ) -> Option < Token > {
419+ fn line_as_line_block_quote ( line : & str ) -> Option < Token < ' _ > > {
411420 if line. starts_with ( '>' ) {
412421 Some ( Token :: BlockQuote ( line) )
413422 } else {
@@ -422,7 +431,7 @@ mod tests {
422431
423432 use pretty_assertions:: assert_eq;
424433
425- fn parse ( s : & str ) -> Vec < Token > {
434+ fn parse ( s : & str ) -> Vec < Token < ' _ > > {
426435 super :: parse ( s, "#" )
427436 }
428437
0 commit comments