š Safe svelte-highlight dynamic style switching
Hides the use of @html
and reduces the risk of XSS.
npm i svelte-highlight-switcher
<script>
import { HighlightSwitcher } from 'svelte-highlight-switcher'
let isDarkMode = false
</script>
<HighlightSwitcher name={isDarkMode ? 'githubDark' : 'github'} />
ā This is equivalent to the following code
<script>
import * as styles from 'svelte-highlight/styles'
let isDarkMode = false
</script>
<svelte:head>
{@html isDarkMode ? styles['githubDark'] : styles['github']}
</svelte:head>
As long as the contents of svelte-highlight/styles
are secure, there is no risk of XSS.