metonym / svelte-highlight

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

Syntax highlighting works locally but breaks in deployed site on Vercel #288

Open hughess opened 11 months ago

hughess commented 11 months ago

We use the Highlight component in our website which is deployed on Vercel. The syntax highlighting will work locally, but will not work once deployed to Vercel. The line numbers and code styling continue to work, just the syntax colours are not applied at all.

When I look in devtools locally, I see each portion of the code split into tags to apply the colours, whereas in the Vercel deployment I only see one tag per line of code, without any colour applied.

We are using the Vercel adapter.

<Highlight language={markdown} {code} let:highlighted>
  <LineNumbers {highlighted} hideBorder {wrapLines}
      --line-number-color="rgb(226 232 240)"
      />
</Highlight>
Snailedlt commented 9 months ago

I'm having similar issues with my app: https://markdown-videos.jorgenkh.no/ The preview build locally also doesn't apply highlighting for HTML.... markdown works fine though.

My code highlighter looks like this:

<script lang="ts">
  import Highlight from 'svelte-highlight';
  import type { LanguageType } from 'svelte-highlight/languages';
  import atomOneDark from 'svelte-highlight/styles/atom-one-dark';

  export let code: string;
  export let language: LanguageType<string>;
  export let style = atomOneDark;
</script>

<svelte:head>
  {@html style}
</svelte:head>

<Highlight {language} {code} />

In case you want to look at more of the code, my project is open-sourced here The relevant code can be found inside apps/web/src/lib

This is how it looks:

Production

image image

Local preview

image image

Local dev

image image

related to https://github.com/Snailedlt/Markdown-Videos/issues/131

MordechaiHadad commented 8 months ago

Having the same issue with https://github.com/MordechaiHadad/svelte-complete

shinokada commented 6 months ago

Highlight didn't work for me either but HighlightSvelte works for me. HighlightSvelte works on Svelte 5. https://svelte-5-ui-lib.vercel.app/components/button

moalhaddar commented 1 week ago

Highlight didn't work for me either but HighlightSvelte works for me. HighlightSvelte works on Svelte 5. https://svelte-5-ui-lib.vercel.app/components/button

For some reason this works for me! I had the same issue, rendering thecode with HighlightSvelte fixed it for me in prod.

Thanks @shinokada

metonym commented 5 days ago

For reference, I've added a Vite + Svelte 5 example set-up.