svelte-highlight 7.4.2 → 7.4.3
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/Highlight.svelte +29 -18
- package/Highlight.svelte.d.ts +71 -12
- package/HighlightAuto.svelte +30 -16
- package/HighlightAuto.svelte.d.ts +68 -18
- package/HighlightSvelte.svelte +27 -20
- package/HighlightSvelte.svelte.d.ts +62 -12
- package/LangTag.svelte +13 -5
- package/LangTag.svelte.d.ts +42 -24
- package/LineNumbers.svelte +26 -16
- package/LineNumbers.svelte.d.ts +83 -75
- package/README.md +2 -0
- package/index.d.ts +1 -1
- package/languages/index.d.ts +1 -1
- package/package.json +14 -705
- package/CHANGELOG.md +0 -428
- package/shared.d.ts +0 -61
package/Highlight.svelte
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
<script>
|
|
2
|
+
// @ts-check
|
|
3
|
+
|
|
4
|
+
/** @type {import("./languages").LanguageType<string>} */
|
|
5
|
+
export let language;
|
|
6
|
+
|
|
7
|
+
/** @type {any} */
|
|
8
|
+
export let code;
|
|
9
|
+
|
|
10
|
+
/** @type {boolean} */
|
|
11
|
+
export let langtag = false;
|
|
12
|
+
|
|
13
|
+
import hljs from "highlight.js/lib/core";
|
|
14
|
+
import { createEventDispatcher, afterUpdate } from "svelte";
|
|
15
|
+
import LangTag from "./LangTag.svelte";
|
|
16
|
+
|
|
17
|
+
const dispatch = createEventDispatcher();
|
|
18
|
+
|
|
19
|
+
/** @type {string} */
|
|
20
|
+
let highlighted = "";
|
|
21
|
+
|
|
22
|
+
afterUpdate(() => {
|
|
23
|
+
if (highlighted) dispatch("highlight", { highlighted });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
$: {
|
|
27
|
+
hljs.registerLanguage(language.name, language.register);
|
|
28
|
+
highlighted = hljs.highlight(code, { language: language.name }).value;
|
|
29
|
+
}
|
|
19
30
|
</script>
|
|
20
31
|
|
|
21
32
|
<slot {highlighted}>
|
package/Highlight.svelte.d.ts
CHANGED
|
@@ -1,13 +1,72 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
import type { LanguageType } from "./languages";
|
|
4
|
+
|
|
5
|
+
export type HighlightProps = HTMLAttributes<HTMLPreElement> & {
|
|
6
|
+
/**
|
|
7
|
+
* Specify the text to highlight.
|
|
8
|
+
*/
|
|
9
|
+
code: any;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Provide the language grammar used to highlight the code.
|
|
13
|
+
* Import languages from `svelte-highlight/languages/*`.
|
|
14
|
+
* @example
|
|
15
|
+
* import typescript from "svelte-highlight/languages/typescript";
|
|
16
|
+
*/
|
|
17
|
+
language: LanguageType<string>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Set to `true` for the language name to be
|
|
21
|
+
* displayed at the top right of the code block.
|
|
22
|
+
*
|
|
23
|
+
* Use style props to customize styles:
|
|
24
|
+
* - `--langtag-background`
|
|
25
|
+
* - `--langtag-color`
|
|
26
|
+
* - `--langtag-border-radius`
|
|
27
|
+
*
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
langtag?: boolean;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Customize the background color of the langtag.
|
|
34
|
+
*/
|
|
35
|
+
"--langtag-background"?: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Customize the text color of the langtag.
|
|
39
|
+
*/
|
|
40
|
+
"--langtag-color"?: string;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Customize the border radius of the langtag.
|
|
44
|
+
*/
|
|
45
|
+
"--langtag-border-radius"?: string;
|
|
7
46
|
};
|
|
8
|
-
|
|
9
|
-
export type HighlightEvents =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
47
|
+
|
|
48
|
+
export type HighlightEvents = {
|
|
49
|
+
highlight: CustomEvent<{
|
|
50
|
+
/**
|
|
51
|
+
* The highlighted HTML as a string.
|
|
52
|
+
* @example "<span>...</span>"
|
|
53
|
+
*/
|
|
54
|
+
highlighted: string;
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type HighlightSlots = {
|
|
59
|
+
default: {
|
|
60
|
+
/**
|
|
61
|
+
* The highlighted HTML as a string.
|
|
62
|
+
* @example "<span>...</span>"
|
|
63
|
+
*/
|
|
64
|
+
highlighted: string;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export default class Highlight extends SvelteComponentTyped<
|
|
69
|
+
HighlightProps,
|
|
70
|
+
HighlightEvents,
|
|
71
|
+
HighlightSlots
|
|
72
|
+
> {}
|
package/HighlightAuto.svelte
CHANGED
|
@@ -1,19 +1,33 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
let
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
<script>
|
|
2
|
+
// @ts-check
|
|
3
|
+
import LangTag from "./LangTag.svelte";
|
|
4
|
+
|
|
5
|
+
/** @type {any} */
|
|
6
|
+
export let code;
|
|
7
|
+
|
|
8
|
+
/** @type {boolean} */
|
|
9
|
+
export let langtag = false;
|
|
10
|
+
|
|
11
|
+
import hljs from "highlight.js";
|
|
12
|
+
import { createEventDispatcher, afterUpdate } from "svelte";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {{ highlighted: string; language: string; }} HighlightEventDetail
|
|
16
|
+
* @type {import("svelte").EventDispatcher<{ highlight: HighlightEventDetail}>}
|
|
17
|
+
*/
|
|
18
|
+
const dispatch = createEventDispatcher();
|
|
19
|
+
|
|
20
|
+
/** @type {string} */
|
|
21
|
+
let highlighted = "";
|
|
22
|
+
|
|
23
|
+
/** @type {string} */
|
|
24
|
+
let language = "";
|
|
25
|
+
|
|
26
|
+
afterUpdate(() => {
|
|
27
|
+
if (highlighted) dispatch("highlight", { highlighted, language });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
$: ({ value: highlighted, language = "" } = hljs.highlightAuto(code));
|
|
17
31
|
</script>
|
|
18
32
|
|
|
19
33
|
<slot {highlighted}>
|
|
@@ -1,19 +1,69 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import type { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
|
|
4
|
+
export type HighlightAutoProps = HTMLAttributes<HTMLPreElement> & {
|
|
5
|
+
/**
|
|
6
|
+
* Specify the text to highlight.
|
|
7
|
+
*/
|
|
8
|
+
code: any;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Set to `true` for the language name to be
|
|
12
|
+
* displayed at the top right of the code block.
|
|
13
|
+
*
|
|
14
|
+
* Use style props to customize styles:
|
|
15
|
+
* - `--langtag-background`
|
|
16
|
+
* - `--langtag-color`
|
|
17
|
+
* - `--langtag-border-radius`
|
|
18
|
+
*
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
langtag?: boolean;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Customize the background color of the langtag.
|
|
25
|
+
*/
|
|
26
|
+
"--langtag-background"?: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Customize the text color of the langtag.
|
|
30
|
+
*/
|
|
31
|
+
"--langtag-color"?: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Customize the border radius of the langtag.
|
|
35
|
+
*/
|
|
36
|
+
"--langtag-border-radius"?: string;
|
|
13
37
|
};
|
|
14
|
-
|
|
15
|
-
export type HighlightAutoEvents =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
38
|
+
|
|
39
|
+
export type HighlightAutoEvents = {
|
|
40
|
+
highlight: CustomEvent<{
|
|
41
|
+
/**
|
|
42
|
+
* The highlighted HTML as a string.
|
|
43
|
+
* @example "<span>...</span>"
|
|
44
|
+
*/
|
|
45
|
+
highlighted: string;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The language name inferred by `highlight.js`.
|
|
49
|
+
* @example "css"
|
|
50
|
+
*/
|
|
51
|
+
language: string;
|
|
52
|
+
}>;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type HighlightAutoSlots = {
|
|
56
|
+
default: {
|
|
57
|
+
/**
|
|
58
|
+
* The highlighted HTML as a string.
|
|
59
|
+
* @example "<span>...</span>"
|
|
60
|
+
*/
|
|
61
|
+
highlighted: string;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default class HighlightAuto extends SvelteComponentTyped<
|
|
66
|
+
HighlightAutoProps,
|
|
67
|
+
HighlightAutoEvents,
|
|
68
|
+
HighlightAutoSlots
|
|
69
|
+
> {}
|
package/HighlightSvelte.svelte
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
afterUpdate
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
<script>
|
|
2
|
+
// @ts-check
|
|
3
|
+
import LangTag from "./LangTag.svelte";
|
|
4
|
+
|
|
5
|
+
/** @type {any} */
|
|
6
|
+
export let code;
|
|
7
|
+
|
|
8
|
+
/** @type {boolean} */
|
|
9
|
+
export let langtag = false;
|
|
10
|
+
|
|
11
|
+
import hljs from "highlight.js/lib/core";
|
|
12
|
+
import xml from "highlight.js/lib/languages/xml";
|
|
13
|
+
import javascript from "highlight.js/lib/languages/javascript";
|
|
14
|
+
import css from "highlight.js/lib/languages/css";
|
|
15
|
+
import { createEventDispatcher, afterUpdate } from "svelte";
|
|
16
|
+
|
|
17
|
+
const dispatch = createEventDispatcher();
|
|
18
|
+
|
|
19
|
+
hljs.registerLanguage("xml", xml);
|
|
20
|
+
hljs.registerLanguage("javascript", javascript);
|
|
21
|
+
hljs.registerLanguage("css", css);
|
|
22
|
+
|
|
23
|
+
afterUpdate(() => {
|
|
24
|
+
if (highlighted) dispatch("highlight", { highlighted });
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
$: highlighted = hljs.highlightAuto(code).value;
|
|
21
28
|
</script>
|
|
22
29
|
|
|
23
30
|
<slot {highlighted}>
|
|
@@ -1,13 +1,63 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
|
|
4
|
+
export type HighlightSvelteProps = HTMLAttributes<HTMLPreElement> & {
|
|
5
|
+
/**
|
|
6
|
+
* Specify the text to highlight.
|
|
7
|
+
*/
|
|
8
|
+
code: any;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Set to `true` for the language name to be
|
|
12
|
+
* displayed at the top right of the code block.
|
|
13
|
+
*
|
|
14
|
+
* Use style props to customize styles:
|
|
15
|
+
* - `--langtag-background`
|
|
16
|
+
* - `--langtag-color`
|
|
17
|
+
* - `--langtag-border-radius`
|
|
18
|
+
*
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
langtag?: boolean;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Customize the background color of the langtag.
|
|
25
|
+
*/
|
|
26
|
+
"--langtag-background"?: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Customize the text color of the langtag.
|
|
30
|
+
*/
|
|
31
|
+
"--langtag-color"?: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Customize the border radius of the langtag.
|
|
35
|
+
*/
|
|
36
|
+
"--langtag-border-radius"?: string;
|
|
7
37
|
};
|
|
8
|
-
|
|
9
|
-
export type HighlightSvelteEvents =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
38
|
+
|
|
39
|
+
export type HighlightSvelteEvents = {
|
|
40
|
+
highlight: CustomEvent<{
|
|
41
|
+
/**
|
|
42
|
+
* The highlighted HTML as a string.
|
|
43
|
+
* @example "<span>...</span>"
|
|
44
|
+
*/
|
|
45
|
+
highlighted: string;
|
|
46
|
+
}>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export type HighlightSvelteSlots = {
|
|
50
|
+
default: {
|
|
51
|
+
/**
|
|
52
|
+
* The highlighted HTML as a string.
|
|
53
|
+
* @example "<span>...</span>"
|
|
54
|
+
*/
|
|
55
|
+
highlighted: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default class HighlightSvelte extends SvelteComponentTyped<
|
|
60
|
+
HighlightSvelteProps,
|
|
61
|
+
HighlightSvelteEvents,
|
|
62
|
+
HighlightSvelteSlots
|
|
63
|
+
> {}
|
package/LangTag.svelte
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
<script
|
|
1
|
+
<script>
|
|
2
|
+
// @ts-check
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
export let
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/** @type {any} */
|
|
5
|
+
export let code;
|
|
6
|
+
|
|
7
|
+
/** @type {string} */
|
|
8
|
+
export let highlighted;
|
|
9
|
+
|
|
10
|
+
/** @type {string} */
|
|
11
|
+
export let languageName = "plaintext";
|
|
12
|
+
|
|
13
|
+
/** @type {boolean} */
|
|
14
|
+
export let langtag = false;
|
|
7
15
|
</script>
|
|
8
16
|
|
|
9
17
|
<pre class:langtag data-language={languageName} {...$$restProps}><code
|
package/LangTag.svelte.d.ts
CHANGED
|
@@ -1,25 +1,43 @@
|
|
|
1
|
-
import { SvelteComponentTyped } from "svelte";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import type { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
|
|
4
|
+
export type LangTagProps = HTMLAttributes<HTMLPreElement> & {
|
|
5
|
+
/**
|
|
6
|
+
* Specify the text to highlight.
|
|
7
|
+
*/
|
|
8
|
+
code: any;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Provide the highlighted code.
|
|
12
|
+
*/
|
|
13
|
+
highlighted: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Provide the language name.
|
|
17
|
+
* @default "plaintext"
|
|
18
|
+
*/
|
|
19
|
+
languageName?: string;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Set to `true` for the language name to be
|
|
23
|
+
* displayed at the top right of the code block.
|
|
24
|
+
*
|
|
25
|
+
* Use style props to customize styles:
|
|
26
|
+
* - `--langtag-background`
|
|
27
|
+
* - `--langtag-color`
|
|
28
|
+
* - `--langtag-border-radius`
|
|
29
|
+
*
|
|
30
|
+
* @default false
|
|
31
|
+
*/
|
|
32
|
+
langtag?: boolean;
|
|
19
33
|
};
|
|
20
|
-
|
|
21
|
-
export type LangTagEvents =
|
|
22
|
-
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
export
|
|
34
|
+
|
|
35
|
+
export type LangTagEvents = {};
|
|
36
|
+
|
|
37
|
+
export type LangTagSlots = {};
|
|
38
|
+
|
|
39
|
+
export default class LangTag extends SvelteComponentTyped<
|
|
40
|
+
LangTagProps,
|
|
41
|
+
LangTagEvents,
|
|
42
|
+
LangTagSlots
|
|
43
|
+
> {}
|
package/LineNumbers.svelte
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
<script>
|
|
2
|
+
// @ts-check
|
|
3
|
+
|
|
4
|
+
/** @type {string} */
|
|
5
|
+
export let highlighted;
|
|
6
|
+
|
|
7
|
+
/** @type {boolean} */
|
|
8
|
+
export let hideBorder = false;
|
|
9
|
+
|
|
10
|
+
/** @type {boolean} */
|
|
11
|
+
export let wrapLines = false;
|
|
12
|
+
|
|
13
|
+
/** @type {number} */
|
|
14
|
+
export let startingLineNumber = 1;
|
|
15
|
+
|
|
16
|
+
/** @type {number[]} */
|
|
17
|
+
export let highlightedLines = [];
|
|
18
|
+
|
|
19
|
+
const DIGIT_WIDTH = 12;
|
|
20
|
+
const MIN_DIGITS = 2;
|
|
21
|
+
const HIGHLIGHTED_BACKGROUND = "rgba(254, 241, 96, 0.2)";
|
|
22
|
+
|
|
23
|
+
$: lines = highlighted.split("\n");
|
|
24
|
+
$: len_digits = lines.length.toString().length;
|
|
25
|
+
$: len = len_digits - MIN_DIGITS < 1 ? MIN_DIGITS : len_digits;
|
|
26
|
+
$: width = len * DIGIT_WIDTH;
|
|
17
27
|
</script>
|
|
18
28
|
|
|
19
29
|
<div style:overflow-x="auto" {...$$restProps}>
|