🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

svelte-highlight

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-highlight

Syntax Highlighting for Svelte using highlight.js

0.2.0
Source
npm
Version published
Weekly downloads
11K
-7.39%
Maintainers
1
Weekly downloads
 
Created
Source

svelte-highlight

NPM Build Coverage

Syntax Highlighting for Svelte using highlight.js.

This component wraps highlight.js to provide syntax highlighting in Svelte 3.

Install

yarn add svelte-highlight

Usage

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

Note: Importing a CSS file in a Svelte file requires the appropriate CSS loader. Refer to the rollup and webpack examples for sample set-ups.

In case you do not want to include a CSS loader, this component exports highlight.js themes in JavaScript. You can 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>

Examples

Changelog

License

MIT

Keywords

svelte

FAQs

Package last updated on 11 Nov 2019

Did you know?

Socket

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.

Install

Related posts