Code Blocks
UtilityDisplays pre-formatted source code, with optional support for Highlight.js syntax highlighting.
Import
Stylesheets
Package
Source
Doc
Dependencies
Examples
<p>Hello Skeleton<p>
.skeleton { color: #bada55; }
const skeleton: string = 'awesome';
Getting Started
Install Highlight.js
Highlight.js is a required dependency to enable syntax highlighting.
npm install highlight.js
Configure Your Project
Apply the following changes to your app's root component (ex: /src/routes/+layout.svelte
for SvelteKit).
import hljs from 'highlight.js';
Import any Highlight.js CSS theme of your choice. Skeleton has provided our custom theme near the top of this page.
import 'highlight.js/styles/github-dark.css';
Finally, import the CodeBlock's writable store and pass a referenced to Highlight.js.
import { storeHighlightJs } from '@skeletonlabs/skeleton';
storeHighlightJs.set(hljs);
Create a Code Block
Syntax highlighting will appear when a valid language alias
is provided to the CodeBlock's
language
prop.
<CodeBlock language="html" code={`<div>This is meta</div>`}></CodeBlock>
Accessibility
Uses pre-wrap
by default to support keyboard-only navigation. Be mindful of color contrast ratios when customizing the design
of this component.