metonym / svelte-highlight

Syntax Highlighting for Svelte using highlight.js
https://svhe.onrender.com
MIT License
262 stars 14 forks source link

feat(styles): support scoped styles #350

Open metonym opened 1 month ago

metonym commented 1 month ago

Alternative to #349 that uses component composition.

<script lang="ts">
  import { Highlight, ScopedStyle } from "svelte-highlight";
  import typescript from "svelte-highlight/languages/typescript";
  import atomOneDark from "svelte-highlight/styles/atom-one-dark.scoped";
  import github from "svelte-highlight/styles/github.scoped";
  import blackMetalDarkFuneral from "svelte-highlight/styles/black-metal-dark-funeral.scoped";

  const code = "const add = (a: number, b: number) => a + b;";
</script>

<ScopedStyle {...atomOneDark}>
  <Highlight language={typescript} {code} />
</ScopedStyle>

<ScopedStyle {...github}>
  <Highlight language={typescript} {code} />
</ScopedStyle>

<ScopedStyle {...blackMetalDarkFuneral}>
  <Highlight language={typescript} {code} />
</ScopedStyle>