@@ -2,9 +2,11 @@ mod fence;
2
2
mod highlight;
3
3
4
4
use std:: ops:: RangeInclusive ;
5
+ use std:: path:: PathBuf ;
5
6
6
7
use errors:: { bail, Result } ;
7
8
use libs:: syntect:: util:: LinesWithEndings ;
9
+ use utils:: fs:: read_file;
8
10
9
11
use crate :: codeblock:: highlight:: SyntaxHighlighter ;
10
12
use config:: highlighting:: { resolve_syntax_and_theme, HighlightSource } ;
@@ -17,11 +19,15 @@ fn opening_html(
17
19
pre_style : Option < String > ,
18
20
pre_class : Option < String > ,
19
21
line_numbers : bool ,
22
+ enable_copy : bool ,
20
23
) -> String {
21
24
let mut html = String :: from ( "<pre" ) ;
22
25
if line_numbers {
23
26
html. push_str ( " data-linenos" ) ;
24
27
}
28
+ if enable_copy {
29
+ html. push_str ( " data-copy" ) ;
30
+ }
25
31
let mut classes = String :: new ( ) ;
26
32
27
33
if let Some ( lang) = language {
@@ -81,11 +87,12 @@ pub struct CodeBlock<'config> {
81
87
line_number_start : usize ,
82
88
highlight_lines : Vec < RangeInclusive < usize > > ,
83
89
hide_lines : Vec < RangeInclusive < usize > > ,
90
+ include : Option < String > ,
84
91
}
85
92
86
93
impl < ' config > CodeBlock < ' config > {
87
94
pub fn new < ' fence_info > (
88
- fence : FenceSettings < ' fence_info > ,
95
+ fence : & FenceSettings < ' fence_info > ,
89
96
config : & ' config Config ,
90
97
// path to the current file if there is one, to point where the error is
91
98
path : Option < & ' config str > ,
@@ -112,19 +119,28 @@ impl<'config> CodeBlock<'config> {
112
119
highlighter. pre_style ( ) ,
113
120
highlighter. pre_class ( ) ,
114
121
fence. line_numbers ,
122
+ fence. enable_copy ,
115
123
) ;
116
124
Ok ( (
117
125
Self {
118
126
highlighter,
119
127
line_numbers : fence. line_numbers ,
120
128
line_number_start : fence. line_number_start ,
121
- highlight_lines : fence. highlight_lines ,
122
- hide_lines : fence. hide_lines ,
129
+ highlight_lines : fence. highlight_lines . clone ( ) ,
130
+ hide_lines : fence. hide_lines . clone ( ) ,
131
+ include : fence. include . map ( |s| s. to_string ( ) ) ,
123
132
} ,
124
133
html_start,
125
134
) )
126
135
}
127
136
137
+ pub fn include ( & self , base : Option < & PathBuf > ) -> Option < String > {
138
+ let path = base?. join ( self . include . as_ref ( ) ?) ;
139
+ let res = read_file ( & path) ;
140
+
141
+ res. ok ( )
142
+ }
143
+
128
144
pub fn highlight ( & mut self , content : & str ) -> String {
129
145
let mut buffer = String :: new ( ) ;
130
146
let mark_style = self . highlighter . mark_style ( ) ;
0 commit comments