@@ -31,6 +31,7 @@ pub fn traverse_directory(
31
31
line_number : bool ,
32
32
relative_paths : bool ,
33
33
exclude_from_tree : bool ,
34
+ no_codeblock : bool ,
34
35
) -> Result < ( String , Vec < serde_json:: Value > ) > {
35
36
// ~~~ Initialization ~~~
36
37
let mut files = Vec :: new ( ) ;
@@ -72,7 +73,7 @@ pub fn traverse_directory(
72
73
if let Ok ( code_bytes) = fs:: read ( path) {
73
74
let code = String :: from_utf8_lossy ( & code_bytes) ;
74
75
75
- let code_block = wrap_code_block ( & code, path. extension ( ) . and_then ( |ext| ext. to_str ( ) ) . unwrap_or ( "" ) , line_number) ;
76
+ let code_block = wrap_code_block ( & code, path. extension ( ) . and_then ( |ext| ext. to_str ( ) ) . unwrap_or ( "" ) , line_number, no_codeblock ) ;
76
77
77
78
if !code. trim ( ) . is_empty ( ) && !code. contains ( char:: REPLACEMENT_CHARACTER ) {
78
79
let file_path = if relative_paths {
@@ -117,7 +118,8 @@ pub fn label<P: AsRef<Path>>(p: P) -> String {
117
118
let path = p. as_ref ( ) ;
118
119
if path. file_name ( ) . is_none ( ) {
119
120
let current_dir = std:: env:: current_dir ( ) . unwrap ( ) ;
120
- current_dir. file_name ( )
121
+ current_dir
122
+ . file_name ( )
121
123
. and_then ( |name| name. to_str ( ) )
122
124
. unwrap_or ( "." )
123
125
. to_owned ( )
@@ -136,11 +138,12 @@ pub fn label<P: AsRef<Path>>(p: P) -> String {
136
138
/// * `code` - The code block to wrap.
137
139
/// * `extension` - The file extension of the code block.
138
140
/// * `line_numbers` - Whether to add line numbers to the code.
141
+ /// * `no_codeblock` - Whether to not wrap the code block with a delimiter.
139
142
///
140
143
/// # Returns
141
144
///
142
145
/// * `String` - The wrapped code block.
143
- fn wrap_code_block ( code : & str , extension : & str , line_numbers : bool ) -> String {
146
+ fn wrap_code_block ( code : & str , extension : & str , line_numbers : bool , no_codeblock : bool ) -> String {
144
147
let delimiter = "`" . repeat ( 3 ) ;
145
148
let mut code_with_line_numbers = String :: new ( ) ;
146
149
@@ -152,8 +155,12 @@ fn wrap_code_block(code: &str, extension: &str, line_numbers: bool) -> String {
152
155
code_with_line_numbers = code. to_string ( ) ;
153
156
}
154
157
155
- format ! (
156
- "{}{}\n {}\n {}" ,
157
- delimiter, extension, code_with_line_numbers, delimiter
158
- )
158
+ if no_codeblock {
159
+ code_with_line_numbers
160
+ } else {
161
+ format ! (
162
+ "{}{}\n {}\n {}" ,
163
+ delimiter, extension, code_with_line_numbers, delimiter
164
+ )
165
+ }
159
166
}
0 commit comments