Skip to content

Commit 5ef5914

Browse files
⚙ Build 2.0.0
1 parent 921a731 commit 5ef5914

File tree

6 files changed

+23
-11
lines changed

6 files changed

+23
-11
lines changed

dist/class/HTMLCodeBlockElement.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default class HTMLCodeBlockElement extends HTMLElement {
3838
* */
3939
get controls(): boolean;
4040
set controls(value: boolean);
41+
set notrim(value: boolean);
4142
static get observedAttributes(): string[];
4243
attributeChangedCallback(attrName: string, oldValue: string, newValue: string): void;
4344
connectedCallback(): void;

dist/class/HTMLCodeBlockElement.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class HTMLCodeBlockElement extends HTMLElement {
8080
#language = '';
8181
/** Actual value of the accessor `controls` */
8282
#controls = false;
83+
/** Actual value of the accessor `notrim` */
84+
#notrim = false;
8385
/** Click event handler of copy button */
8486
#onClickButton = (() => {
8587
let key = -1;
@@ -120,12 +122,7 @@ class HTMLCodeBlockElement extends HTMLElement {
120122
return;
121123
}
122124
this.#observer.disconnect();
123-
const src = (() => {
124-
if (/[^\n]\n$/.test(this.#value)) {
125-
return `${this.#value}\n`;
126-
}
127-
return this.#value;
128-
})();
125+
const src = this.#notrim ? this.#value : this.#value.trim();
129126
/** The resulting syntax-highlighted markup */
130127
const { markup } = HTMLCodeBlockElement.highlight({
131128
src,
@@ -223,8 +220,21 @@ class HTMLCodeBlockElement extends HTMLElement {
223220
}
224221
this.#render();
225222
}
223+
set notrim(value) {
224+
if (this.#notrim === value) {
225+
return;
226+
}
227+
this.#notrim = value;
228+
if (this.#notrim) {
229+
this.setAttribute('notrim', '');
230+
}
231+
else {
232+
this.removeAttribute('notrim');
233+
}
234+
this.#render();
235+
}
226236
static get observedAttributes() {
227-
return ['label', 'language', 'controls'];
237+
return ['label', 'language', 'controls', 'notrim'];
228238
}
229239
attributeChangedCallback(attrName, oldValue, newValue) {
230240
if (oldValue === newValue) {
@@ -240,6 +250,7 @@ class HTMLCodeBlockElement extends HTMLElement {
240250
break;
241251
// boolean
242252
case 'controls':
253+
case 'notrim':
243254
this[attrName] = typeof newValue === 'string';
244255
}
245256
}
@@ -318,6 +329,7 @@ class HTMLCodeBlockElement extends HTMLElement {
318329
this.#label = a11yName.textContent || '';
319330
this.#language = this.getAttribute('language') || '';
320331
this.#controls = this.getAttribute('controls') !== null;
332+
this.#notrim = this.getAttribute('notrim') !== null;
321333
this.#a11yName = a11yName;
322334
this.#copyButton = copyButton;
323335
this.#codeBlock = codeElm;

dist/effects/add-style.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ style.textContent = `
2626
background: #75758a;
2727
box-sizing: border-box;
2828
}
29-
3029
code-block button {
3130
all: unset;
3231
outline: revert;

lib/html-code-block-element.all.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/html-code-block-element.common.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/html-code-block-element.core.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)