
Product
Introducing Socket MCP for Claude Desktop
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
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 svelte-highlight
There are two ways to use highlight.js styles: through a CSS stylesheet loader or the svelte:head
API.
Importing a CSS stylesheet in Svelte requires a CSS loader. Refer to the rollup and webpack examples for sample set-ups.
<script>
import Highlight from 'svelte-highlight';
import { typescript } from 'svelte-highlight/languages';
import 'svelte-highlight/styles/github.css';
</script>
<Highlight language={typescript}>
{`function add(a: number, b: number) {
return a + b;
}
const sum = add(1, 2);`}
</Highlight>
svelte:head
This component exports highlight.js themes in JavaScript. Simply import the theme as JavaScript 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';
</script>
<svelte:head>
{@html github}
</svelte:head>
<Highlight language={typescript}>
{`function add(a: number, b: number) {
return a + b;
}
const sum = add(1, 2);`}
</Highlight>
code
PropCode passed to the slot (like in the above examples) will not dynamically update. Use the code
prop for code that changes.
<script>
import Highlight from 'svelte-highlight';
import { typescript } from 'svelte-highlight/languages';
import 'svelte-highlight/styles/github.css';
let count = 0;
function increment() {
count += 1;
}
$: code = `let count = ${count};`;
</script>
<button on:click={increment}>Increment</button>
<Highlight language={typescript} {code} />
For custom language highlighting, pass a name
and register
function to the language prop.
Refer to the highlight.js language definition guide for more info.
<script>
import Highlight from 'svelte-highlight';
import hljs from 'highlight.js';
const language = {
name: 'custom-lang',
register: (hljs) => {
return {
// ...
}
}
}
const code = 'custom language';
</script>
<Highlight {language} {code} />
0.3.2 - 2019-12-12
FAQs
Svelte component library for highlighting code using highlight.js
The npm package svelte-highlight receives a total of 9,581 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
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
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.