diff --git a/src/Highlight.svelte b/src/Highlight.svelte index eab75759..fcb5dde0 100644 --- a/src/Highlight.svelte +++ b/src/Highlight.svelte @@ -34,7 +34,7 @@ /** * Specify the source code to highlight. */ - code?: any; + code: any; /** * Provide the language grammar used to highlight the code. @@ -42,7 +42,7 @@ * @example * import typescript from "svelte-highlight/languages/typescript"; */ - language?: Language; + language: Language; /** * Set to `true` for the language name to be @@ -77,12 +77,9 @@ interface $$Events extends Events {} - export let language: Language = { - name: undefined, - register: undefined, - }; + export let language: Language; - export let code = undefined; + export let code: any; export let langtag = false; diff --git a/src/HighlightAuto.svelte b/src/HighlightAuto.svelte index 1653dd1c..3b5fa30f 100644 --- a/src/HighlightAuto.svelte +++ b/src/HighlightAuto.svelte @@ -9,7 +9,7 @@ /** * Specify the source code to highlight. */ - code?: any; + code: any; /** * Set to `true` for the language name to be @@ -44,7 +44,7 @@ interface $$Events extends Events {} - export let code = undefined; + export let code; export let langtag = false; @@ -60,9 +60,7 @@ if (highlighted) dispatch("highlight", { highlighted }); }); - $: if (code) { - ({ value: highlighted, language } = hljs.highlightAuto(code)); - } + $: ({ value: highlighted, language } = hljs.highlightAuto(code)); diff --git a/src/HighlightSvelte.svelte b/src/HighlightSvelte.svelte index 4e9b874b..1590d146 100644 --- a/src/HighlightSvelte.svelte +++ b/src/HighlightSvelte.svelte @@ -9,7 +9,7 @@ /** * Specify the source code to highlight. */ - code?: any; + code: any; /** * Set to `true` for the language name to be @@ -44,7 +44,7 @@ interface $$Events extends Events {} - export let code = undefined; + export let code; export let langtag = false; diff --git a/tests/SvelteHighlight.test.svelte b/tests/SvelteHighlight.test.svelte index 42dc109c..6e091481 100644 --- a/tests/SvelteHighlight.test.svelte +++ b/tests/SvelteHighlight.test.svelte @@ -55,7 +55,17 @@ - + { + return { + contains: [], + }; + }, + }} +/>
{highlighted}