svelte-highlight 7.4.8 → 7.6.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.
@@ -2,49 +2,76 @@ import type { SvelteComponentTyped } from "svelte";
2
2
  import type { HTMLAttributes } from "svelte/elements";
3
3
  import type { LanguageType } from "./languages";
4
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
-
5
+ export type LangtagProps = {
19
6
  /**
20
7
  * Set to `true` for the language name to be
21
8
  * displayed at the top right of the code block.
22
9
  *
23
10
  * Use style props to customize styles:
11
+ * - `--langtag-top`
12
+ * - `--langtag-right`
24
13
  * - `--langtag-background`
25
14
  * - `--langtag-color`
26
15
  * - `--langtag-border-radius`
16
+ * - `--langtag-padding`
27
17
  *
28
18
  * @default false
29
19
  */
30
20
  langtag?: boolean;
31
21
 
22
+ /**
23
+ * Customize the top position of the langtag.
24
+ * @default 0
25
+ */
26
+ "--langtag-top"?: string | number;
27
+
28
+ /**
29
+ * Customize the right position of the langtag.
30
+ * @default 0
31
+ */
32
+ "--langtag-right"?: string | number;
33
+
32
34
  /**
33
35
  * Customize the background color of the langtag.
36
+ * @default "inherit"
34
37
  */
35
38
  "--langtag-background"?: string;
36
39
 
37
40
  /**
38
41
  * Customize the text color of the langtag.
42
+ * @default "inherit"
39
43
  */
40
44
  "--langtag-color"?: string;
41
45
 
42
46
  /**
43
47
  * Customize the border radius of the langtag.
48
+ * @default 0
44
49
  */
45
50
  "--langtag-border-radius"?: string;
51
+
52
+ /**
53
+ * Customize the padding of the langtag.
54
+ * @default "1em"
55
+ */
56
+ "--langtag-padding"?: string;
46
57
  };
47
58
 
59
+ export type HighlightProps = HTMLAttributes<HTMLPreElement> &
60
+ LangtagProps & {
61
+ /**
62
+ * Specify the text to highlight.
63
+ */
64
+ code: any;
65
+
66
+ /**
67
+ * Provide the language grammar used to highlight the code.
68
+ * Import languages from `svelte-highlight/languages/*`.
69
+ * @example
70
+ * import typescript from "svelte-highlight/languages/typescript";
71
+ */
72
+ language: LanguageType<string>;
73
+ };
74
+
48
75
  export type HighlightEvents = {
49
76
  highlight: CustomEvent<{
50
77
  /**
@@ -1,40 +1,14 @@
1
1
  import type { SvelteComponentTyped } from "svelte";
2
2
  import type { HTMLAttributes } from "svelte/elements";
3
+ import type { LangtagProps } from "./Highlight.svelte";
3
4
 
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;
37
- };
5
+ export type HighlightAutoProps = HTMLAttributes<HTMLPreElement> &
6
+ LangtagProps & {
7
+ /**
8
+ * Specify the text to highlight.
9
+ */
10
+ code: any;
11
+ };
38
12
 
39
13
  export type HighlightAutoEvents = {
40
14
  highlight: CustomEvent<{
@@ -1,40 +1,14 @@
1
1
  import type { SvelteComponentTyped } from "svelte";
2
2
  import type { HTMLAttributes } from "svelte/elements";
3
+ import type { LangtagProps } from "./Highlight.svelte";
3
4
 
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;
37
- };
5
+ export type HighlightSvelteProps = HTMLAttributes<HTMLPreElement> &
6
+ LangtagProps & {
7
+ /**
8
+ * Specify the text to highlight.
9
+ */
10
+ code: any;
11
+ };
38
12
 
39
13
  export type HighlightSvelteEvents = {
40
14
  highlight: CustomEvent<{
package/LangTag.svelte CHANGED
@@ -27,14 +27,14 @@
27
27
  .langtag::after {
28
28
  content: attr(data-language);
29
29
  position: absolute;
30
- top: 0;
31
- right: 0;
32
- padding: 1em;
30
+ top: var(--langtag-top, 0);
31
+ right: var(--langtag-right, 0);
33
32
  display: flex;
34
33
  align-items: center;
35
34
  justify-content: center;
36
35
  background: var(--langtag-background, inherit);
37
36
  color: var(--langtag-color, inherit);
38
- border-radius: var(--langtag-border-radius);
37
+ border-radius: var(--langtag-border-radius, 0);
38
+ padding: var(--langtag-padding, 1em);
39
39
  }
40
40
  </style>
@@ -1,36 +1,25 @@
1
1
  import type { SvelteComponentTyped } from "svelte";
2
2
  import type { HTMLAttributes } from "svelte/elements";
3
+ import type { LangtagProps } from "./Highlight.svelte";
3
4
 
4
- export type LangTagProps = HTMLAttributes<HTMLPreElement> & {
5
- /**
6
- * Specify the text to highlight.
7
- */
8
- code: any;
5
+ export type LangTagProps = HTMLAttributes<HTMLPreElement> &
6
+ LangtagProps & {
7
+ /**
8
+ * Specify the text to highlight.
9
+ */
10
+ code: any;
9
11
 
10
- /**
11
- * Provide the highlighted code.
12
- */
13
- highlighted: string;
12
+ /**
13
+ * Provide the highlighted code.
14
+ */
15
+ highlighted: string;
14
16
 
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;
33
- };
17
+ /**
18
+ * Provide the language name.
19
+ * @default "plaintext"
20
+ */
21
+ languageName?: string;
22
+ };
34
23
 
35
24
  export type LangTagEvents = {};
36
25
 
package/README.md CHANGED
@@ -283,9 +283,12 @@ See the [Languages page](SUPPORTED_LANGUAGES.md) for a list of supported languag
283
283
 
284
284
  | Style prop | Description | Default value |
285
285
  | :---------------------- | :------------------------------ | :------------ |
286
+ | --langtag-top | Top position of the langtag | `0` |
287
+ | --langtag-right | Right position of the langtag | `0` |
286
288
  | --langtag-background | Background color of the langtag | `inherit` |
287
289
  | --langtag-color | Text color of the langtag | `inherit` |
288
290
  | --langtag-border-radius | Border radius of the langtag | `0` |
291
+ | --langtag-padding | Padding of the langtag | `1em` |
289
292
 
290
293
  ```svelte
291
294
  <script>
@@ -297,12 +300,15 @@ See the [Languages page](SUPPORTED_LANGUAGES.md) for a list of supported languag
297
300
  <HighlightAuto {code} langtag />
298
301
  ```
299
302
 
300
- ```css
301
- [data-language="css"] {
302
- --langtag-background: linear-gradient(135deg, #2996cf, 80%, white);
303
- --langtag-color: #fff;
304
- --langtag-border-radius: 8px;
305
- }
303
+ ```svelte
304
+ <HighlightAuto
305
+ {code}
306
+ langtag
307
+ --langtag-background="linear-gradient(135deg, #2996cf, 80%, white)"
308
+ --langtag-color="#fff"
309
+ --langtag-border-radius="6px"
310
+ --langtag-padding="0.5rem"
311
+ />
306
312
  ```
307
313
 
308
314
  ## Custom Language
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-highlight",
3
- "version": "7.4.8",
3
+ "version": "7.6.0",
4
4
  "license": "MIT",
5
5
  "description": "Svelte component library for highlighting code using highlight.js",
6
6
  "author": "Eric Liu (https://github.com/metonym)",