File tree Expand file tree Collapse file tree 2 files changed +15
-19
lines changed Expand file tree Collapse file tree 2 files changed +15
-19
lines changed Original file line number Diff line number Diff line change 34
34
border-top : 1px solid # 000 ;
35
35
}
36
36
</ style >
37
- <!-- <script src="./lib/html-code-block-element.common.min.js" defer></script> -->
37
+ <!-- <script src=".. /lib/html-code-block-element.common.min.js" defer></script> -->
38
38
<!-- <script src="https://cdn.jsdelivr.net/npm/@heppokofrontend/html-code-block-element/lib/html-code-block-element.core.min.js" defer></script> -->
39
39
< script src ="https://cdn.jsdelivr.net/npm/@heppokofrontend/html-code-block-element/lib/html-code-block-element.common.min.js " defer > </ script >
40
40
<!-- <script src="https://cdn.jsdelivr.net/npm/@heppokofrontend/html-code-block-element/lib/html-code-block-element.all.min.js" defer></script> -->
@@ -69,18 +69,14 @@ <h3>Source</h3>
69
69
70
70
< code-block language ="html ">
71
71
< textarea > < code-block language ="html ">
72
- < textarea >
73
- < script > console . log ( true ) ; </ script >
74
- </textarea>
72
+ < textarea > < script > console . log ( true ) ; </ script > </textarea>
75
73
</ code-block > </ textarea >
76
74
</ code-block >
77
75
78
76
< h3 > Result</ h3 >
79
77
80
78
< code-block language ="html ">
81
- < textarea >
82
- < script > console . log ( true ) ; </ script >
83
- </ textarea >
79
+ < textarea > < script > console . log ( true ) ; </ script > </ textarea >
84
80
</ code-block >
85
81
86
82
< h2 > Playground</ h2 >
@@ -96,31 +92,26 @@ <h2>Playground</h2>
96
92
< h2 > Hello world</ h2 >
97
93
98
94
< p class ="example "> This is sample markup.</ p >
99
- </ div > `;
100
- </ textarea >
95
+ </ div > `;</ textarea >
101
96
</ code-block >
102
97
103
98
< code-block language ="js " label ="Example: CSS " controls >
104
- < textarea >
105
- cb.language = 'css';
99
+ < textarea > cb.language = 'css';
106
100
cb.value = `body {
107
101
/* This is sample css */
108
102
font-size: 100px;
109
- }`;
110
- </ textarea >
103
+ }`;</ textarea >
111
104
</ code-block >
112
105
113
106
< code-block language ="js " label ="Example: JSON " controls >
114
- < textarea >
115
- cb.language = 'json';
107
+ < textarea > cb.language = 'json';
116
108
cb.value = `{
117
109
"items": [
118
110
100,
119
111
null,
120
112
"This is sample json"
121
113
]
122
- }`;
123
- </ textarea >
114
+ }`;</ textarea >
124
115
</ code-block >
125
116
</ main >
126
117
< footer >
Original file line number Diff line number Diff line change @@ -123,7 +123,12 @@ export default class HTMLCodeBlockElement extends HTMLElement {
123
123
}
124
124
125
125
set value ( src : string ) {
126
- this . #value = src ;
126
+ if ( / \n $ / . test ( src ) ) {
127
+ this . #value = `${ src } \n` ;
128
+ } else {
129
+ this . #value = src ;
130
+ }
131
+
127
132
this . #render( ) ;
128
133
}
129
134
@@ -304,7 +309,7 @@ export default class HTMLCodeBlockElement extends HTMLElement {
304
309
/* -------------------------------------------------------------------------
305
310
* Hard private props initialize
306
311
* ---------------------------------------------------------------------- */
307
- this . #value = ( this . textContent || '' ) . replace ( / ^ \n / , '' ) . replace ( / \n \n $ / , '' ) ;
312
+ this . #value = ( this . textContent || '' ) . replace ( / ^ \n / , '' ) ;
308
313
this . #label = a11yName . textContent || '' ;
309
314
this . #language = this . getAttribute ( 'language' ) || '' ;
310
315
this . #controls = this . getAttribute ( 'controls' ) !== null ;
You can’t perform that action at this time.
0 commit comments