File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
assets/mods/code-block-panel/js
layouts/partials/code-block-panel/assets Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,13 @@ import { default as params } from '@params';
2
2
import snackbar from 'mods/snackbar/js/index.ts' ;
3
3
import i18n from './i18n' ;
4
4
5
+ const isTrue = ( val : string | boolean ) : boolean => {
6
+ if ( typeof val === 'boolean' ) {
7
+ return val
8
+ }
9
+ return val !== '' && val !== 'false' && val !== '0'
10
+ }
11
+
5
12
export default class Panel {
6
13
private highlight : HTMLElement
7
14
@@ -15,12 +22,16 @@ export default class Panel {
15
22
}
16
23
17
24
init ( ) {
18
- if ( ! params . line_nos ) {
25
+ const highlight = this . code . closest ( '.highlight' )
26
+ if ( ! isTrue ( highlight ?. getAttribute ( 'data-line-nos' ) ?? params . line_nos ) ) {
19
27
this . code . classList . add ( 'code-no-ln' )
20
28
}
21
- if ( params . wrap ) {
29
+ if ( isTrue ( highlight ?. getAttribute ( 'data-wrap' ) ?? params . wrap ) ) {
22
30
this . code . classList . add ( 'code-wrap' )
23
31
}
32
+ if ( isTrue ( highlight ?. getAttribute ( 'data-expand' ) ?? params . expand ) ) {
33
+ this . expand ( )
34
+ }
24
35
25
36
this . pre = this . code . parentElement as HTMLElement
26
37
this . highlight = this . pre . parentElement as HTMLElement
@@ -47,7 +58,7 @@ export default class Panel {
47
58
return Array . from ( this . code . querySelectorAll ( ':scope > span' ) )
48
59
}
49
60
50
- private maxHeight
61
+ private maxHeight : string
51
62
52
63
private maxLines ( ) {
53
64
const lines = this . lines ( )
Original file line number Diff line number Diff line change 8
8
"max_lines" 10
9
9
"line_nos" true
10
10
"wrap" false
11
+ "expand" false
11
12
}}
12
13
{{- $i18n := newScratch }}
13
14
{{- $sites := .Sites }}
You can’t perform that action at this time.
0 commit comments