Skip to content

Commit 985654c

Browse files
🚿 Update comments and eslint --fix
1 parent 6801bfc commit 985654c

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

src/class/HTMLCodeBlockElement.ts

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,27 @@ export namespace Endgine {
1111
export type callback = (src: string, options?: Options) => Result;
1212
}
1313

14+
/** The HTML element for highlighting code fragments. */
1415
export default class HTMLCodeBlockElement extends HTMLElement {
1516
/**
1617
* Returns the result of highlighting the received source code string.
1718
* Before running `customElements.define()`,
1819
* you need to assign it directly to `HTMLCodeBlockElement.highlight`.
1920
* @param src - Source code string for highlight
2021
* @param options - Option for highlight
21-
* @returns - Object of the highlight result
22+
* @return - Object of the highlight result
2223
*/
23-
static highlight: Endgine.callback = () => {
24+
static highlight: Endgine.callback = (src: string, options: any) => {
2425
throw new TypeError('The syntax highlighting engine is not set to `HTMLCodeBlockElement.highlight`.');
26+
return {markup: ''};
2527
};
2628

2729
/** Slot elements for Shadow DOM content */
2830
#slots = (() => {
2931
/**
3032
* @param name - The value of name attribute for the slot element
31-
* @returns - The slot element
33+
* @param id - The value of id attribute for the slot element
34+
* @return - The slot element
3235
*/
3336
const mkslot = (name: string, id?: string) => {
3437
const slot = document.createElement('slot');
@@ -67,10 +70,13 @@ export default class HTMLCodeBlockElement extends HTMLElement {
6770
/** Click event handler of copy button */
6871
#onClickButton = (() => {
6972
let key = -1;
70-
const copy = (): Promise<void> => {
71-
const value = this.#value.replace(/\n$/, '');
72-
73-
if (navigator.clipboard){
73+
/**
74+
* Write to the clipboard.
75+
* @param value - String to be saved to the clipboard
76+
* @return - A promise
77+
*/
78+
const copy = (value: string): Promise<void> => {
79+
if (navigator.clipboard) {
7480
return navigator.clipboard.writeText(value);
7581
}
7682

@@ -84,21 +90,26 @@ export default class HTMLCodeBlockElement extends HTMLElement {
8490
textarea.remove();
8591
r();
8692
});
87-
}
93+
};
8894

8995
return async () => {
96+
const value = this.#value.replace(/\n$/, '');
97+
9098
clearTimeout(key);
9199

92-
await copy();
100+
await copy(value);
93101

94102
this.#copyButton.textContent = 'Copied!';
95103
key = window.setTimeout(() => {
96104
this.#copyButton.textContent = 'Copy';
97105
}, 1500);
98106
};
99107
})();
100-
/** Outputs the resulting syntax-highlighted markup to the DOM. */
101-
#render = function (this: HTMLCodeBlockElement) {
108+
/**
109+
* Outputs the resulting syntax-highlighted markup to the DOM.
110+
* @param this - instance
111+
*/
112+
#render = function(this: HTMLCodeBlockElement) {
102113
if (!this.parentNode) {
103114
return;
104115
}
@@ -109,7 +120,7 @@ export default class HTMLCodeBlockElement extends HTMLElement {
109120
}
110121

111122
return this.#value;
112-
})()
123+
})();
113124

114125
/** The resulting syntax-highlighted markup */
115126
const {markup} = HTMLCodeBlockElement.highlight(src, {
@@ -128,7 +139,7 @@ export default class HTMLCodeBlockElement extends HTMLElement {
128139
this.append(this.#codeWrap);
129140
}
130141

131-
/** @returns - Syntax Highlighted Source Code */
142+
/** @return - Syntax Highlighted Source Code */
132143
get value() {
133144
return this.#value;
134145
}
@@ -140,7 +151,7 @@ export default class HTMLCodeBlockElement extends HTMLElement {
140151

141152
/**
142153
* The name of code block
143-
* @returns - The value of the label attribute
154+
* @return - The value of the label attribute
144155
*/
145156
get label() {
146157
return this.#label;
@@ -160,7 +171,7 @@ export default class HTMLCodeBlockElement extends HTMLElement {
160171

161172
/**
162173
* Language Mode
163-
* @returns - The value of the language attribute
174+
* @return - The value of the language attribute
164175
*/
165176
get language() {
166177
return this.#language;
@@ -180,7 +191,7 @@ export default class HTMLCodeBlockElement extends HTMLElement {
180191

181192
/**
182193
* Flag to display the UI
183-
* @returns - With or without controls attribute
194+
* @return - With or without controls attribute
184195
* */
185196
get controls() {
186197
return this.#controls;
@@ -207,9 +218,9 @@ export default class HTMLCodeBlockElement extends HTMLElement {
207218
}
208219

209220
attributeChangedCallback(
210-
attrName: string,
211-
oldValue: string,
212-
newValue: string,
221+
attrName: string,
222+
oldValue: string,
223+
newValue: string,
213224
) {
214225
if (oldValue === newValue) {
215226
return;
@@ -294,7 +305,7 @@ export default class HTMLCodeBlockElement extends HTMLElement {
294305
span.textContent = 'Code Block';
295306

296307
return span;
297-
})()
308+
})();
298309
const container = (() => {
299310
const div = document.createElement('div');
300311

src/utils/highlight.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import {HLJSApi, HighlightOptions} from 'highlight.js';
33
/**
44
* Callback maker for highlight.js
55
* @param endgine - A library for performing syntax highlighting.
6-
* @returns - A function for HTMLCodeBlockElement.highlight
6+
* @return - A function for HTMLCodeBlockElement.highlight
77
*/
88
export const mkHighlightCallback = (endgine: HLJSApi) => (
9-
src: string,
10-
options?: HighlightOptions,
9+
src: string,
10+
options?: HighlightOptions,
1111
) => {
1212
const hljs: HLJSApi = endgine;
1313

@@ -18,8 +18,8 @@ export const mkHighlightCallback = (endgine: HLJSApi) => (
1818
) {
1919
return {
2020
markup: hljs.highlight(
21-
src,
22-
options,
21+
src,
22+
options,
2323
).value,
2424
};
2525
}

0 commit comments

Comments
 (0)