File tree 2 files changed +26
-22
lines changed
2 files changed +26
-22
lines changed Original file line number Diff line number Diff line change @@ -129,15 +129,13 @@ impl<'config> CodeBlock<'config> {
129
129
) )
130
130
}
131
131
132
- pub fn include ( & self , base : Option < & PathBuf > ) -> Option < String > {
133
- let path = base?. join ( self . include . as_ref ( ) ?) ;
134
- let res = read_file ( & path) ;
135
- match res {
136
- Ok ( content) => Some ( content) ,
137
- Err ( e) => {
138
- eprintln ! ( "Warning: Failed to include {:?}: {}" , path, e) ;
139
- None
140
- }
132
+ pub fn include ( & self , base : Option < & PathBuf > ) -> Result < Option < String > > {
133
+ if let Some ( base) = base {
134
+ let path = base. join ( & self . include . as_ref ( ) . expect ( "No include path" ) ) ;
135
+ let content = read_file ( & path) ?;
136
+ Ok ( Some ( content) )
137
+ } else {
138
+ Ok ( None )
141
139
}
142
140
}
143
141
Original file line number Diff line number Diff line change @@ -577,19 +577,25 @@ pub fn markdown_to_html(
577
577
}
578
578
Event :: End ( TagEnd :: CodeBlock { .. } ) => {
579
579
if let Some ( ref mut code_block) = code_block {
580
- let inner = code_block
581
- . include (
582
- context
583
- . parent_absolute
584
- . map ( |e| {
585
- path. map ( |p| e. join ( PathBuf :: from ( p) . parent ( ) . unwrap ( ) ) )
586
- } )
587
- . flatten ( )
588
- . as_ref ( ) ,
589
- )
590
- . unwrap_or ( accumulated_block. clone ( ) ) ;
591
- let html = code_block. highlight ( & inner) ;
592
- events. push ( Event :: Html ( html. into ( ) ) ) ;
580
+ let maybe_inner = code_block. include (
581
+ context
582
+ . parent_absolute
583
+ . map ( |e| path. map ( |p| e. join ( PathBuf :: from ( p) . parent ( ) . unwrap ( ) ) ) )
584
+ . flatten ( )
585
+ . as_ref ( ) ,
586
+ ) ;
587
+ match maybe_inner {
588
+ Ok ( i) => {
589
+ let inner = i. as_ref ( ) . unwrap_or ( & accumulated_block) ;
590
+ let html = code_block. highlight ( & inner) ;
591
+ events. push ( Event :: Html ( html. into ( ) ) ) ;
592
+ }
593
+ Err ( e) => {
594
+ error = Some ( e) ;
595
+ break ;
596
+ }
597
+ }
598
+
593
599
accumulated_block. clear ( ) ;
594
600
}
595
601
You can’t perform that action at this time.
0 commit comments