svelte-highlight 7.14.1 → 7.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AnsiOutput.svelte CHANGED
@@ -111,6 +111,8 @@
111
111
 
112
112
  /** Foreground CSS, with auto-contrast override when needed. */
113
113
  function foregroundCss(segment) {
114
+ // Concealed text is rendered transparent (layout and copy text stay).
115
+ if (segment.conceal) return "transparent";
114
116
  if (autoContrast && segment.bg) {
115
117
  const bg = colorToRgb(segment.bg);
116
118
  const fg = segment.fg
@@ -129,6 +131,7 @@
129
131
  if (segment.dim) names.push("dim");
130
132
  if (segment.italic) names.push("italic");
131
133
  if (segment.underline) names.push("underline");
134
+ if (segment.strikethrough) names.push("strikethrough");
132
135
  return names.length ? names.join(" ") : undefined;
133
136
  }
134
137
 
@@ -147,13 +150,16 @@
147
150
  text: segment.text,
148
151
  class: classNames(segment),
149
152
  style: inlineStyle(segment),
153
+ link: segment.link,
150
154
  }));
151
155
  </script>
152
156
 
153
157
  <pre class="ansi" {...$$restProps}><code
154
- >{#each segments as segment}<span class={segment.class} style={segment.style}
158
+ >{#each segments as segment}{#if segment.link}<a href={segment.link} rel="noopener noreferrer" class={segment.class} style={segment.style}
159
+ >{segment.text}</a
160
+ >{:else}<span class={segment.class} style={segment.style}
155
161
  >{segment.text}</span
156
- >{/each}</code
162
+ >{/if}{/each}</code
157
163
  ></pre>
158
164
 
159
165
  <style>
@@ -187,7 +193,20 @@
187
193
  font-style: italic;
188
194
  }
189
195
 
190
- .underline {
196
+ .ansi a {
197
+ color: inherit;
198
+ text-decoration: none;
199
+ }
200
+
201
+ .ansi .underline {
191
202
  text-decoration: underline;
192
203
  }
204
+
205
+ .ansi .strikethrough {
206
+ text-decoration: line-through;
207
+ }
208
+
209
+ .ansi .underline.strikethrough {
210
+ text-decoration: underline line-through;
211
+ }
193
212
  </style>
package/CopyButton.svelte CHANGED
@@ -8,6 +8,13 @@
8
8
  */
9
9
  export let copy = (code) => navigator.clipboard.writeText(code);
10
10
 
11
+ /**
12
+ * Transform `code` before it is passed to `copy`. Defaults to identity.
13
+ * The transformed string is what `on:copy` reports in `detail.code`.
14
+ * @type {(code: string) => string}
15
+ */
16
+ export let transform = (code) => code;
17
+
11
18
  /** @type {number} */
12
19
  export let timeout = 2_000;
13
20
 
@@ -36,9 +43,10 @@
36
43
 
37
44
  try {
38
45
  copying = true;
39
- await copy(code);
46
+ const transformed = transform(code);
47
+ await copy(transformed);
40
48
  copied = true;
41
- dispatch("copy", { code });
49
+ dispatch("copy", { code: transformed });
42
50
  timeoutId = setTimeout(() => {
43
51
  copied = false;
44
52
  }, timeout);
@@ -13,6 +13,13 @@ export type CopyButtonProps = HTMLButtonAttributes & {
13
13
  */
14
14
  copy?: (code: string) => void | Promise<void>;
15
15
 
16
+ /**
17
+ * Transform `code` before it is passed to `copy`. Defaults to identity.
18
+ * The transformed string is what `on:copy` reports in `detail.code`.
19
+ * @default (code) => code
20
+ */
21
+ transform?: (code: string) => string;
22
+
16
23
  /**
17
24
  * How long the "copied" state lasts (ms).
18
25
  * @default 2000
@@ -91,7 +98,7 @@ export type CopyButtonProps = HTMLButtonAttributes & {
91
98
  export type CopyButtonEvents = {
92
99
  copy: CustomEvent<{
93
100
  /**
94
- * The code that was copied.
101
+ * The code that was copied, after `transform` is applied.
95
102
  */
96
103
  code: string;
97
104
  }>;
package/Highlight.svelte CHANGED
@@ -23,7 +23,8 @@
23
23
 
24
24
  $: {
25
25
  hljs.registerLanguage(language.name, language.register);
26
- highlighted = hljs.highlight(code, { language: language.name }).value;
26
+ const source = typeof code === "string" ? code : String(code ?? "");
27
+ highlighted = hljs.highlight(source, { language: language.name }).value;
27
28
  }
28
29
  </script>
29
30
 
@@ -30,7 +30,7 @@
30
30
  });
31
31
 
32
32
  $: ({ value: highlighted, language = "" } = hljs.highlightAuto(
33
- code,
33
+ typeof code === "string" ? code : String(code ?? ""),
34
34
  languageNames,
35
35
  ));
36
36
  </script>