File tree 6 files changed +20
-2
lines changed
6 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ mathjax-support = true
9
9
10
10
[output .html .playpen ]
11
11
editable = true
12
+ line-numbers = true
12
13
13
14
[output .html .search ]
14
15
limit-results = 20
Original file line number Diff line number Diff line change @@ -179,6 +179,7 @@ Available configuration options for the `[output.html.playpen]` table:
179
179
- ** editable:** Allow editing the source code. Defaults to ` false ` .
180
180
- ** copy-js:** Copy JavaScript files for the editor to the output directory.
181
181
Defaults to ` true ` .
182
+ - ** line-numbers** Display line numbers on editable sections of code. Requires both ` editable ` and ` copy-js ` to be ` true ` . Defaults to ` false ` .
182
183
183
184
[ Ace ] : https://ace.c9.io/
184
185
@@ -228,6 +229,7 @@ git-repository-icon = "fa-github"
228
229
[output .html .playpen ]
229
230
editable = false
230
231
copy-js = true
232
+ line-numbers = false
231
233
232
234
[output .html .search ]
233
235
enable = true
Original file line number Diff line number Diff line change @@ -479,13 +479,16 @@ pub struct Playpen {
479
479
/// Copy JavaScript files for the editor to the output directory?
480
480
/// Default: `true`.
481
481
pub copy_js : bool ,
482
+ /// Display line numbers on playpen snippets
483
+ pub line_numbers : bool ,
482
484
}
483
485
484
486
impl Default for Playpen {
485
487
fn default ( ) -> Playpen {
486
488
Playpen {
487
489
editable : false ,
488
490
copy_js : true ,
491
+ line_numbers : false ,
489
492
}
490
493
}
491
494
}
@@ -620,6 +623,7 @@ mod tests {
620
623
let playpen_should_be = Playpen {
621
624
editable : true ,
622
625
copy_js : true ,
626
+ line_numbers : false ,
623
627
} ;
624
628
let html_should_be = HtmlConfig {
625
629
curly_quotes : true ,
Original file line number Diff line number Diff line change @@ -441,6 +441,9 @@ fn make_data(
441
441
442
442
if html_config. playpen . editable && html_config. playpen . copy_js {
443
443
data. insert ( "playpen_js" . to_owned ( ) , json ! ( true ) ) ;
444
+ if html. playpen . line_numbers {
445
+ data. insert ( "playpen_line_numbers" . to_owned ( ) , json ! ( true ) ) ;
446
+ }
444
447
}
445
448
446
449
let search = html_config. search . clone ( ) ;
Original file line number Diff line number Diff line change 230
230
</script >
231
231
{{ /if }}
232
232
233
+ {{ #if playpen_line_numbers }}
234
+ <script type =" text/javascript" >
235
+ window .playpen_line_numbers = true ;
236
+ </script >
237
+ {{ /if }}
238
+
233
239
{{ #if playpen_js }}
234
240
<script src =" {{ path_to_root }} ace.js" type =" text/javascript" charset =" utf-8" ></script >
235
241
<script src =" {{ path_to_root }} editor.js" type =" text/javascript" charset =" utf-8" ></script >
Original file line number Diff line number Diff line change @@ -6,12 +6,14 @@ window.editors = [];
6
6
}
7
7
8
8
Array . from ( document . querySelectorAll ( '.editable' ) ) . forEach ( function ( editable ) {
9
+ let display_line_numbers = window . playpen_line_numbers || false ;
10
+
9
11
let editor = ace . edit ( editable ) ;
10
12
editor . setOptions ( {
11
13
highlightActiveLine : false ,
12
14
showPrintMargin : false ,
13
- showLineNumbers : false ,
14
- showGutter : false ,
15
+ showLineNumbers : display_line_numbers ,
16
+ showGutter : display_line_numbers ,
15
17
maxLines : Infinity ,
16
18
fontSize : "0.875em" // please adjust the font size of the code in general.css
17
19
} ) ;
You can’t perform that action at this time.
0 commit comments