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';
22import snackbar from 'mods/snackbar/js/index.ts' ;
33import i18n from './i18n' ;
44
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+
512export default class Panel {
613 private highlight : HTMLElement
714
@@ -15,12 +22,16 @@ export default class Panel {
1522 }
1623
1724 init ( ) {
18- if ( ! params . line_nos ) {
25+ const highlight = this . code . closest ( '.highlight' )
26+ if ( ! isTrue ( highlight ?. getAttribute ( 'data-line-nos' ) ?? params . line_nos ) ) {
1927 this . code . classList . add ( 'code-no-ln' )
2028 }
21- if ( params . wrap ) {
29+ if ( isTrue ( highlight ?. getAttribute ( 'data-wrap' ) ?? params . wrap ) ) {
2230 this . code . classList . add ( 'code-wrap' )
2331 }
32+ if ( isTrue ( highlight ?. getAttribute ( 'data-expand' ) ?? params . expand ) ) {
33+ this . expand ( )
34+ }
2435
2536 this . pre = this . code . parentElement as HTMLElement
2637 this . highlight = this . pre . parentElement as HTMLElement
@@ -47,7 +58,7 @@ export default class Panel {
4758 return Array . from ( this . code . querySelectorAll ( ':scope > span' ) )
4859 }
4960
50- private maxHeight
61+ private maxHeight : string
5162
5263 private maxLines ( ) {
5364 const lines = this . lines ( )
Original file line number Diff line number Diff line change 88 "max_lines" 10
99 "line_nos" true
1010 "wrap" false
11+ "expand" false
1112}}
1213{{- $i18n := newScratch }}
1314{{- $sites := .Sites }}
You can’t perform that action at this time.
0 commit comments