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 3434 border-top : 1px solid # 000 ;
3535 }
3636 </ 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> -->
3838 <!-- <script src="https://cdn.jsdelivr.net/npm/@heppokofrontend/html-code-block-element/lib/html-code-block-element.core.min.js" defer></script> -->
3939 < script src ="https://cdn.jsdelivr.net/npm/@heppokofrontend/html-code-block-element/lib/html-code-block-element.common.min.js " defer > </ script >
4040 <!-- <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>
6969
7070< code-block language ="html ">
7171< textarea > < code-block language ="html ">
72- < textarea >
73- < script > console . log ( true ) ; </ script >
74- </textarea>
72+ < textarea > < script > console . log ( true ) ; </ script > </textarea>
7573</ code-block > </ textarea >
7674</ code-block >
7775
7876< h3 > Result</ h3 >
7977
8078< code-block language ="html ">
81- < textarea >
82- < script > console . log ( true ) ; </ script >
83- </ textarea >
79+ < textarea > < script > console . log ( true ) ; </ script > </ textarea >
8480</ code-block >
8581
8682< h2 > Playground</ h2 >
@@ -96,31 +92,26 @@ <h2>Playground</h2>
9692 < h2 > Hello world</ h2 >
9793
9894 < p class ="example "> This is sample markup.</ p >
99- </ div > `;
100- </ textarea >
95+ </ div > `;</ textarea >
10196</ code-block >
10297
10398< code-block language ="js " label ="Example: CSS " controls >
104- < textarea >
105- cb.language = 'css';
99+ < textarea > cb.language = 'css';
106100cb.value = `body {
107101 /* This is sample css */
108102 font-size: 100px;
109- }`;
110- </ textarea >
103+ }`;</ textarea >
111104</ code-block >
112105
113106< code-block language ="js " label ="Example: JSON " controls >
114- < textarea >
115- cb.language = 'json';
107+ < textarea > cb.language = 'json';
116108cb.value = `{
117109 "items": [
118110 100,
119111 null,
120112 "This is sample json"
121113 ]
122- }`;
123- </ textarea >
114+ }`;</ textarea >
124115</ code-block >
125116</ main >
126117< footer >
Original file line number Diff line number Diff line change @@ -123,7 +123,12 @@ export default class HTMLCodeBlockElement extends HTMLElement {
123123 }
124124
125125 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+
127132 this . #render( ) ;
128133 }
129134
@@ -304,7 +309,7 @@ export default class HTMLCodeBlockElement extends HTMLElement {
304309 /* -------------------------------------------------------------------------
305310 * Hard private props initialize
306311 * ---------------------------------------------------------------------- */
307- this . #value = ( this . textContent || '' ) . replace ( / ^ \n / , '' ) . replace ( / \n \n $ / , '' ) ;
312+ this . #value = ( this . textContent || '' ) . replace ( / ^ \n / , '' ) ;
308313 this . #label = a11yName . textContent || '' ;
309314 this . #language = this . getAttribute ( 'language' ) || '' ;
310315 this . #controls = this . getAttribute ( 'controls' ) !== null ;
You can’t perform that action at this time.
0 commit comments