File tree 1 file changed +25
-6
lines changed
packages/site-kit/src/lib/components 1 file changed +25
-6
lines changed Original file line number Diff line number Diff line change 35
35
const ts = !! parent .querySelector (' .ts-toggle:checked' );
36
36
const code = parent .querySelector (` pre:${ts ? ' last' : ' first' }-of-type code ` ) as HTMLElement ;
37
37
38
- let result = ' ' ;
39
- for (const node of code .childNodes ?? []) {
40
- if (! (node as HTMLElement ).classList .contains (' deleted' )) {
41
- result += node .textContent ! .trimEnd () + ' \n ' ;
42
- }
38
+ navigator .clipboard .writeText (get_text (code ));
39
+ }
40
+ }
41
+
42
+ function get_text(node : HTMLElement ) {
43
+ let result = ' ' ;
44
+
45
+ for (const child of node .childNodes ?? []) {
46
+ if (child .nodeType === 3 ) {
47
+ result += (child as Text ).data ;
43
48
}
44
49
45
- navigator .clipboard .writeText (result .trim ());
50
+ if (child .nodeType === 1 ) {
51
+ const classes = (child as HTMLElement ).classList ;
52
+
53
+ if (classes .contains (' deleted' ) || classes .contains (' twoslash-popup-container' )) {
54
+ continue ;
55
+ }
56
+
57
+ if (classes .contains (' twoslash-meta-line' ) || classes .contains (' twoslash-error-line' )) {
58
+ result += ' \n ' ;
59
+ } else {
60
+ result += get_text (child as HTMLElement );
61
+ }
62
+ }
46
63
}
64
+
65
+ return result ;
47
66
}
48
67
</script >
49
68
You can’t perform that action at this time.
0 commit comments