Skip to content

Commit

Permalink
breaking: mark code/language props as required
Browse files Browse the repository at this point in the history
Closes #215
  • Loading branch information
metonym committed Jul 1, 2022
1 parent f66e5ed commit 63f5933
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
15 changes: 6 additions & 9 deletions src/Highlight.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
/**
* Specify the source code to highlight.
*/
code?: any;
code: any;
/**
* Provide the language to highlight the code.
* Import languages from `svelte-highlight/languages/*`.
*/
language?: Language;
language: Language;
/**
* Set to `true` for the language name to be
Expand All @@ -51,12 +51,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;
Expand All @@ -71,7 +68,7 @@
if (highlighted) dispatch("highlight", { highlighted });
});
$: if (language.name && language.register) {
$: if (language?.name && language?.register) {
hljs.registerLanguage(language.name, language.register);
highlighted = hljs.highlight(code, { language: language.name }).value;
}
Expand All @@ -81,7 +78,7 @@
<!-- prettier-ignore -->
<pre
class:langtag
data-language={language.name || "plaintext"}
data-language={language?.name || "plaintext"}
{...$$restProps}><code class="hljs">{#if highlighted !== undefined}{@html highlighted}{:else}{code}{/if}</code></pre>
</slot>

Expand Down
8 changes: 3 additions & 5 deletions src/HighlightAuto.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Specify the source code to highlight.
*/
code?: any;
code: any;
/**
* Set to `true` for the language name to be
Expand All @@ -20,7 +20,7 @@
interface $$Events extends Events {}
export let code = undefined;
export let code;
export let langtag = false;
Expand All @@ -36,9 +36,7 @@
if (highlighted) dispatch("highlight", { highlighted });
});
$: if (code) {
({ value: highlighted, language } = hljs.highlightAuto(code));
}
$: ({ value: highlighted, language } = hljs.highlightAuto(code));
</script>

<slot {highlighted}>
Expand Down
4 changes: 2 additions & 2 deletions src/HighlightSvelte.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Specify the source code to highlight.
*/
code?: any;
code: any;
/**
* Set to `true` for the language name to be
Expand All @@ -20,7 +20,7 @@
interface $$Events extends Events {}
export let code = undefined;
export let code;
export let langtag = false;
Expand Down

0 comments on commit 63f5933

Please sign in to comment.