@@ -65,17 +65,10 @@ pub fn parse<'a>(input: &'a str, comment_string: &str) -> Vec<Token<'a>> {
65
65
} else if let Some ( fence) = line_as_code_fence ( line) {
66
66
toks. push ( Token :: FencedCodeBlock ( line) ) ;
67
67
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 {
71
70
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
+ }
79
72
toks. push ( t) ;
80
73
} else if is_line_blank_or_whitespace ( line) {
81
74
if toks. last ( ) != Some ( & Token :: VerticalSpace ) {
@@ -179,6 +172,22 @@ fn extend_prose_buffer_with_line<'input>(
179
172
None
180
173
}
181
174
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
+
182
191
fn is_line_blank_or_whitespace ( line : & str ) -> bool {
183
192
line. chars ( ) . all ( char:: is_whitespace)
184
193
}
@@ -260,7 +269,7 @@ fn is_line_trailer(line: &str) -> bool {
260
269
}
261
270
}
262
271
263
- fn line_as_list_item ( line : & str ) -> Option < Token > {
272
+ fn line_as_list_item ( line : & str ) -> Option < Token < ' _ > > {
264
273
enum LiState {
265
274
New ,
266
275
IndentSp1 ,
@@ -349,7 +358,7 @@ fn line_as_list_item(line: &str) -> Option<Token> {
349
358
} )
350
359
}
351
360
352
- fn line_as_code_fence ( line : & ' _ str ) -> Option < CodeFence > {
361
+ fn line_as_code_fence ( line : & str ) -> Option < CodeFence < ' _ > > {
353
362
enum FenceState {
354
363
New ,
355
364
IndentSp1 ,
@@ -407,7 +416,7 @@ fn line_as_code_fence(line: &'_ str) -> Option<CodeFence> {
407
416
}
408
417
}
409
418
410
- fn line_as_line_block_quote ( line : & str ) -> Option < Token > {
419
+ fn line_as_line_block_quote ( line : & str ) -> Option < Token < ' _ > > {
411
420
if line. starts_with ( '>' ) {
412
421
Some ( Token :: BlockQuote ( line) )
413
422
} else {
@@ -422,7 +431,7 @@ mod tests {
422
431
423
432
use pretty_assertions:: assert_eq;
424
433
425
- fn parse ( s : & str ) -> Vec < Token > {
434
+ fn parse ( s : & str ) -> Vec < Token < ' _ > > {
426
435
super :: parse ( s, "#" )
427
436
}
428
437
0 commit comments