
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
svelte-highlight
Advanced tools
Syntax Highlighting for Svelte using highlight.js.
This component wraps highlight.js to provide syntax highlighting in Svelte 3.
yarn add -D svelte-highlight
# OR
npm i -D svelte-highlight
There are two ways to apply highlight.js
styles:
svelte:head
This component exports highlight.js
themes in JavaScript. Import the theme from svelte-highlight/styles
and inject it using the svelte:head API.
<script>
import { Highlight } from "svelte-highlight";
import { typescript } from "svelte-highlight/languages";
import { github } from "svelte-highlight/styles";
$: code = `const add = (a: number, b: number) => a + b;`;
</script>
<svelte:head>
{@html github}
</svelte:head>
<Highlight language="{typescript}" {code} />
Importing a CSS StyleSheet in Svelte requires a CSS file loader. Refer to examples/webpack for a sample set-up.
<script>
import { Highlight } from "svelte-highlight";
import { typescript } from "svelte-highlight/languages";
import "svelte-highlight/styles/github.css";
$: code = `const add = (a: number, b: number) => a + b;`;
</script>
<Highlight language="{typescript}" {code} />
This library uses highlightjs-svelte to highlight Svelte code.
<script>
import { HighlightSvelte } from "svelte-highlight";
import { github } from "svelte-highlight/styles";
$: code = `<script>
let count = 0;
<\/script>
<button on:click="{() => (count += 1)}">Increment {count}<\/button>`;
</script>
<svelte:head>
{@html github}
</svelte:head>
<HighlightSvelte {code} />
For custom language highlighting, pass a name
and register
function to the language prop.
Refer to the highlight.js language definition guide for guidance.
<script>
import { Highlight } from "svelte-highlight";
import hljs from "highlight.js";
const language = {
name: "custom-language",
register: (hljs) => {
return {
/** custom language rules */
};
},
};
const code = "custom language";
</script>
<Highlight {language} {code} />
Property name | Value |
---|---|
code | string |
language | object { name: string ; register: hljs => object } |
...$$restProps | (forwarded to the pre element) |
The following events are forwarded to the pre
element:
<Highlight
language="{typescript}"
code="{code}"
on:highlight="{(e) => {
console.log(e.detail.highlighted); // "<span>...</span>"
}}"
/>
Svelte version 3.31 or greater is required to use this component with TypeScript.
FAQs
Svelte component library for highlighting code using highlight.js
The npm package svelte-highlight receives a total of 8,659 weekly downloads. As such, svelte-highlight popularity was classified as popular.
We found that svelte-highlight demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.