-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Code highlighting for docs (#18)
* Added shiki * Moved stores to `docs` module * Resolved pnpm-lock conflict * Fixed code block issues * Better specificy, fixed @html warning
- Loading branch information
Showing
17 changed files
with
2,014 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script lang="ts"> | ||
import MoonlightDark from '$docs/themes/moonlight-dark.json'; | ||
import MoonlightLight from '$docs/themes/moonlight-light.json'; | ||
import { page } from '$app/stores'; | ||
import type { BuiltinLanguage, SpecialLanguage } from 'shiki'; | ||
interface Props { | ||
code: string; | ||
lang: BuiltinLanguage | SpecialLanguage; | ||
} | ||
let { code, lang = 'text' }: Props = $props(); | ||
const html = $derived( | ||
// eslint-disable-next-line svelte/valid-compile | ||
$page.data.highlighter.codeToHtml(code.trim(), { | ||
lang, | ||
themes: { | ||
// @ts-expect-error - Shiki theme type is annoyingly strict | ||
dark: MoonlightDark, | ||
// @ts-expect-error - Shiki theme type is annoyingly strict | ||
light: MoonlightLight | ||
} | ||
}) | ||
); | ||
</script> | ||
|
||
<!-- eslint-disable svelte/no-at-html-tags --> | ||
{@html html} | ||
|
||
<!-- eslint-enable svelte/no-at-html-tags --> | ||
|
||
<style lang="postcss"> | ||
:global(pre.shiki) { | ||
@apply p-4 text-sm rounded-md whitespace-pre-wrap; | ||
} | ||
</style> |
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...b/components/Navigation/Navigation.svelte → ...s/components/Navigation/Navigation.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...b/components/PageHeader/PageHeader.svelte → ...s/components/PageHeader/PageHeader.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.