Skip to content

jill64/svelte-highlight-switcher

Repository files navigation

svelte-highlight-switcher

npm-version npm-license npm-download-month npm-min-size ci.yml website

๐Ÿ“ Safe svelte-highlight dynamic style switching

Hides the use of @html and reduces the risk of XSS.

Installation

npm i svelte-highlight-switcher

Example

<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.

License

MIT