@@ -240,7 +240,7 @@ impl Keyword {
240240
241241pub struct Parser {
242242 state_machine : ParserStateMachine ,
243- comment_symbol : char ,
243+ comment_symbol : String ,
244244 start_comment : String ,
245245 end_comment : String ,
246246 code_block : String ,
@@ -255,7 +255,7 @@ impl Parser {
255255 let start_comment = config
256256 . comment_start_string
257257 . unwrap_or_else ( || "/**" . to_string ( ) ) ;
258- let comment_symbol = config. comment_prefix . unwrap_or ( '*' ) ;
258+ let comment_symbol = config. comment_prefix . unwrap_or ( "*" . to_string ( ) ) ;
259259 let end_comment = config
260260 . comment_end_string
261261 . unwrap_or_else ( || "*/" . to_string ( ) ) ;
@@ -329,7 +329,7 @@ impl Parser {
329329
330330 fn trim_article_line ( & self , line : String ) -> String {
331331 line. trim_start ( )
332- . trim_start_matches ( self . comment_symbol )
332+ . trim_start_matches ( & self . comment_symbol )
333333 . trim_start ( )
334334 . to_string ( )
335335 }
@@ -361,13 +361,22 @@ impl Parser {
361361 fn parse_text < ' a > ( & self , line : & ' a str ) -> & ' a str {
362362 let empty_comment_line = format ! ( "{} " , self . comment_symbol) ;
363363 let trimmed_line = line. trim_start ( ) ;
364+ let space_symbol = ' ' ;
364365
365- if trimmed_line. starts_with ( & empty_comment_line) {
366- & trimmed_line[ 2 ..]
367- } else if trimmed_line. starts_with ( ' ' ) || trimmed_line. starts_with ( self . comment_symbol ) {
368- & trimmed_line[ 1 ..]
369- } else {
370- trimmed_line
366+ match trimmed_line {
367+ l if l. starts_with ( & empty_comment_line) =>
368+ {
369+ & l[ empty_comment_line. chars ( ) . count ( ) ..]
370+ }
371+ l if trimmed_line. starts_with ( space_symbol) =>
372+ {
373+ & l[ 1 ..]
374+ }
375+ l if l. starts_with ( & self . comment_symbol ) =>
376+ {
377+ & l[ self . comment_symbol . chars ( ) . count ( ) ..]
378+ }
379+ _ => & trimmed_line
371380 }
372381 }
373382
@@ -569,6 +578,44 @@ pub fn test () {}
569578 assert_eq ! ( articles, expected_result) ;
570579}
571580
581+ #[ test]
582+ fn parse_articles_with_custom_comment_symbol ( ) {
583+ let mut parser = Parser :: new ( {
584+ config:: Config {
585+ project_path : "test" . to_string ( ) ,
586+ files_patterns : vec ! [ "test" . to_string( ) ] ,
587+ docs_folder : None ,
588+ repository_host : None ,
589+ comment_start_string : Some ( "/@-" . to_string ( ) ) ,
590+ comment_prefix : Some ( "@-" . to_string ( ) ) ,
591+ comment_end_string : Some ( "@-/" . to_string ( ) ) ,
592+ mdbook : None ,
593+ book_name : None ,
594+ book_build_dir : None ,
595+ repositories : None ,
596+ plugins_dir : None ,
597+ }
598+ } ) ;
599+ let file_content = "
600+ /@-
601+ @- @Article Test article
602+ @- some text
603+ @-/
604+ pub fn test () {}
605+ " ;
606+
607+ let articles = parser. parse_file ( file_content, "" ) ;
608+ let expected_result = vec ! [ Article {
609+ topic: String :: from( "Test article" ) ,
610+ content: String :: from( "some text" ) ,
611+ path: "" . to_string( ) ,
612+ start_line: 3 ,
613+ end_line: 4 ,
614+ } ] ;
615+
616+ assert_eq ! ( articles, expected_result) ;
617+ }
618+
572619#[ test]
573620fn ignore_comments_with_ignore_mark ( ) {
574621 let mut parser = Parser :: new ( get_test_config ( ) ) ;
0 commit comments