code snippet docs

Code Snippet

Text container in a style that is best fit for a monospace font.

Published Last updated: 2.25.1 Change log Github NPM
Twig Usage
  {% include "@bolt-components-code-snippet/code-snippet.twig" with {
  display: "block",
  lang: "html",
  content: "Some code snippet"
} only %}
Schema
Note: when assigning component props as HTML attributes on a web component, make sure to use kebab-case.
Prop Name Description Type Default Value Option(s)
display

Defines if the code text is inline or block.

string block
  • block or inline
lang

Language of the code text.

string html
  • css , html , js , scss , twig
syntax

Toggle between a light and dark syntax highlighting, or turn it off. Separate from Bolt theming.

string light
  • light , dark , none
Install Install
  npm install @bolt/components-code-snippet
Dependencies @bolt/core-v3.x @bolt/lazy-queue prismjs

code snippet

Code snippet can be a block of code, and display is set to block by default.

  display: block;
margin: 0 0 1.65rem 0;

Well, code snippet can also be inline like this display:inline; when you set display to be inline instead.

block:

  <header>
  <h1>Headline</h1>
</header>

inline:

<header><h1>Headline</h1></header>

css:

  .my-css {
  display: block;
}

scss:

  .my-scss {
  @include my-mixin;
}

html:

  <header>
  <h1>Headline</h1>
</header>

javascript:

  import { polyfillLoader } from '@bolt/core-v3.x/polyfills';

twig:

  {% include "@bolt-components-code-snippet/code-snippet.twig" with {
  display: "block",
  lang: "html",
  content: "Some code snippet"
} only %}

light:

  <header>
  <h1>Headline</h1>
</header>

dark:

  <header>
  <h1>Headline</h1>
</header>

none:

  <header>
  <h1>Headline</h1>
</header>

code snippet web component

Web Component Usage Bolt Code Snippet is a web component, you can simply use <bolt-code-snippet> in the markup to make it render.

Headline

<bolt-code-snippet lang="html"> <header> <h1>Headline</h1> </header> </bolt-code-snippet>
Prop Usage Configure the code snippet with the properties specified in the schema.
.my-scss { @include my-mixin; }
<bolt-code-snippet lang="scss" display="block" syntax="light"> .my-scss { @include my-mixin; } </bolt-code-snippet>