No Preview

Sorry, but you either have no stories or none are selected somehow.

If the problem persists, check the browser console, or the terminal you've run Storybook from.

deckgo-highlight-code

The "Highlight Code" component is an extra component which let you highlight code easily.

To highlight your code, this component is using Prism.js from Lea Verou and James DiGioia.

Moreover, per default, your code will be displayed in form of a stylish "windowed" card as the amazing carbon, the tool to create and share beautiful images of your source code, would do.

Installation

This component can be added to your web application with following methods.

If you are using our developer kit to create a presention, this component is already included

Using DeckDeckGo Highlight Code from a CDN

It's recommended to use unpkg to use the DeckDeckGo Code from a CDN. To do so, add the following include script in the main HTML file of your project:

<script type="module" src="https://unpkg.com/@deckdeckgo/highlight-code@latest/dist/deckdeckgo-highlight-code/deckdeckgo-highlight-code.esm.js"></script>

Install DeckDeckGo Highlight Code from NPM

Install DeckDeckGo - Highlight Code in your project from npm using the following command:

npm install @deckdeckgo/highlight-code

Framework integration

The Stencil documentation provide examples of framework integration for Angular, React, Vue and Ember.

That being said, commonly, you might either import or load it:

Import

import '@deckdeckgo/highlight-code';

Loader

import { defineCustomElements as deckDeckGoElement } from '@deckdeckgo/highlight-code/dist/loader';
deckDeckGoElement();

Usage

The <deckgo-highlight-code/> Web Component will highlight your code using Prism.js.

You could inject a <code/> tag using slot or provide an URI to the file containing your code.

If you are displaying your code in an Ubuntu terminal, you could also displays a text in the toolbar (header) using the slot user.

Properties

PropertyAttributeDescriptionTypeDefault
editableeditableDisplay a button user can click to edit the code. Edition has to find place on the comsumer side, the button emits an eventbooleanfalse
editableLabeleditable-labelAn optional label for the aria-label attribute of the editable buttonstringundefined
highlightLineshighlight-linesIf you wish to highlight some lines of your code. The lines number should be provided as a number (one line) or numbers separated with coma or dash (many lines), group separated with space. For example: 1 3,5 8 14-17 which highlight lines 1, 3 to 5, 8 and 14 to 17stringundefined
languagelanguageDefine the language to be used for the syntax highlighting. The list of supported languages is defined by Prism.jsstring'javascript'
lineNumbersline-numbersDisplay the number of the lines of codebooleanfalse
terminalterminalPresent the code in a stylish "windowed" cardDeckdeckgoHighlightCodeTerminal.CARBON \| DeckdeckgoHighlightCodeTerminal.NONE \| DeckdeckgoHighlightCodeTerminal.PAPYRS \| DeckdeckgoHighlightCodeTerminal.UBUNTUDeckdeckgoHighlightCodeTerminal.CARBON
themethemeThe theme of the selected terminal (applied only in case of carbon)DeckdeckgoHighlightCodeCarbonThemeDeckdeckgoHighlightCodeCarbonTheme.DRACULA

Events

EventDescriptionType
prismLanguageErrorEmitted when a language could not be loaded. The component fallback to javascript language to display the code anyway.CustomEvent<string>
prismLanguageLoadedEmitted when a language is fetched and loadedCustomEvent<string>

Methods

load() => Promise<void>

Load or reload the component

Returns

Type: Promise<void>

nextHighlight() => Promise<void>

Animate highlighted lines and, apply "focus" on next group

Returns

Type: Promise<void>

prevHighlight() => Promise<void>

Animate highlighted lines and, apply "focus" on previous group

Returns

Type: Promise<void>

Slots

SlotDescription
"code"A <code/> element to highlight
"user"A user name for the Ubuntu terminal

CSS Custom Properties

NameDescription
--deckgo-highlight-code-backgroundUbuntu code background
--deckgo-highlight-code-border-radiusThe border radius of the displayed code
--deckgo-highlight-code-carbon-backgroundThe background property of the host container @default #282a36
--deckgo-highlight-code-carbon-borderThe border property of the host container
--deckgo-highlight-code-carbon-border-radiusThe border-radius property of the host container @default 4px
--deckgo-highlight-code-carbon-box-shadowThe box-shadow property of the host container @default rgba(0, 0, 0, 0.55) 0 8px 16px)
--deckgo-highlight-code-carbon-colorThe color property of the host container @default white
--deckgo-highlight-code-carbon-displayThe display property of the host container @default block
--deckgo-highlight-code-carbon-header-button-border-radiusThe border-radius of a button of the card header @default 50%
--deckgo-highlight-code-carbon-header-button-green-backgroundThe background of the third button of the card header @default #27c93f
--deckgo-highlight-code-carbon-header-button-heightThe height of a button of the card header @default 0.75em
--deckgo-highlight-code-carbon-header-button-marginThe margin of a button of the card header @default 0.5em 0.375em 0.5em 0
--deckgo-highlight-code-carbon-header-button-red-backgroundThe background of the first button of the card header @default #ff5f56
--deckgo-highlight-code-carbon-header-button-widthThe width of a button of the card header @default 0.75em
--deckgo-highlight-code-carbon-header-button-yellow-backgroundThe background of the second button of the card header @default #ffbd2e
--deckgo-highlight-code-carbon-header-marginThe margin property of the card header @default 0
--deckgo-highlight-code-carbon-header-paddingThe padding property of the card header. @default 8px 16px
--deckgo-highlight-code-carbon-marginThe margin property of the host container @default 16px 0
--deckgo-highlight-code-carbon-overflowThe overflow property of the host container. @default auto
--deckgo-highlight-code-carbon-toolbar-displayThe display property of the toolbar container @default bloack
--deckgo-highlight-code-colorUbuntu container color @default inherit
--deckgo-highlight-code-container-align-itemsThe attribute align-items of the code's container
--deckgo-highlight-code-container-displayThe attribute display of the code's container @default bloack
--deckgo-highlight-code-container-flex-directionThe attribute flex-direction of the code's container
--deckgo-highlight-code-container-heightThe attribute height of the code's container
--deckgo-highlight-code-container-justify-contentThe attribute justify-content of the code's container
--deckgo-highlight-code-container-widthThe attribute width of the code's container
--deckgo-highlight-code-directionThe direction of the displayed code @default ltr
--deckgo-highlight-code-displayThe display property of the code @default block
--deckgo-highlight-code-font-familyUbuntu font family @default Ubuntu mono
--deckgo-highlight-code-font-sizeThe size of the font for the code
--deckgo-highlight-code-heightHeight property of the shadowed code block @default 100%
--deckgo-highlight-code-line-backgroundThe background of the lines you wish to highlight
--deckgo-highlight-code-line-border-bottomThe border-bottom property of the lines you wish to highlight
--deckgo-highlight-code-line-border-topThe border-top property of the lines you wish to highlight
--deckgo-highlight-code-line-font-weightThe font-weight of the lines you wish to highlight
--deckgo-highlight-code-line-heightThe line height of the font for the code
--deckgo-highlight-code-line-numbers-backgroundThe background property of the line numbers
--deckgo-highlight-code-line-numbers-border-rightThe border right property of the line numbers @default 1px solid rgba(var(--deckgo-highlight-code-token-comment-rgb, 98, 114, 164), 0.32)
--deckgo-highlight-code-line-numbers-colorThe color property of the line numbers @default var(--deckgo-highlight-code-token-comment, #6272a4)
--deckgo-highlight-code-line-opacityThe opacity of the lines you do wish to highlight @default 1
--deckgo-highlight-code-line-transitionTransition between lowlight and highlight @default all 0.35s ease-in
--deckgo-highlight-code-marginThe margin property of the code container @default 0 0 1em
--deckgo-highlight-code-paddingThe padding of the displayed code @default 2px 0 0
--deckgo-highlight-code-scrollIn case you would like to change the scroll property of the shadowed code block @default auto
--deckgo-highlight-code-text-alignThe text alignment of your code @default start
--deckgo-highlight-code-token-atruleHighlighted code tokens atrule, attr-value, keyword @default #ff79c6
--deckgo-highlight-code-token-commentHighlighted code tokens comment, prolog, doctype and cdata @default #6272a4
--deckgo-highlight-code-token-functionHighlighted code function, class-name @default #ffb86c
--deckgo-highlight-code-token-operatorHighlighted code tokens operator, entity, url, string @default #ff79c6
--deckgo-highlight-code-token-propertyHighlighted code tokens property, tag, boolean, number, constant, symbol, deleted @default #bd93f9
--deckgo-highlight-code-token-punctuationHighlighted code token punctuation @default #6272a4
--deckgo-highlight-code-token-regexHighlighted code tokens regex, important, variable @default #f1fa8c
--deckgo-highlight-code-token-selectorHighlighted code tokens selector, attr-name, string, char, builtin, inserted @default #50fa7b
--deckgo-highlight-code-ubuntu-backgroundThe background property of the host container @default #4c1e3d
--deckgo-highlight-code-ubuntu-borderThe border property of the host container
--deckgo-highlight-code-ubuntu-border-radiusThe border-radius property of the host container @default 6px 6px 0 0
--deckgo-highlight-code-ubuntu-box-shadowThe box-shadow property of the host container @default 2px 4px 10px rgba(0, 0, 0, 0.5)
--deckgo-highlight-code-ubuntu-colorThe color property of the host container @default #ddd
--deckgo-highlight-code-ubuntu-displayThe display property of the host container @default block
--deckgo-highlight-code-ubuntu-header-backgroundThe background property of the card header @default linear-gradient(#504b45 0%, #3c3b37 100%)
--deckgo-highlight-code-ubuntu-header-button-border-radiusThe border-radius of a button of the card header @default 50%
--deckgo-highlight-code-ubuntu-header-button-box-shadowThe box-shadow of a button of the card header @default 0px 0px 1px 0px #41403a, 0px 1px 1px 0px #474642
--deckgo-highlight-code-ubuntu-header-button-close-backgroundThe close button background of the card header @default linear-gradient(#f37458 0%, #de4c12 100%)
--deckgo-highlight-code-ubuntu-header-button-close-borderThe close button border of the card header
--deckgo-highlight-code-ubuntu-header-button-colorThe color of a button of the card header @default black
--deckgo-highlight-code-ubuntu-header-button-font-sizeThe font-size of a button of the card header @default 0.4375em
--deckgo-highlight-code-ubuntu-header-button-heightThe height of a button of the card header @default 12px
--deckgo-highlight-code-ubuntu-header-button-marginThe margin of a button of the card header @default 0 0.25em 0 0
--deckgo-highlight-code-ubuntu-header-button-maximize-backgroundThe maximize button background of the card header @default linear-gradient(#7d7871 0%, #595953 100%)
--deckgo-highlight-code-ubuntu-header-button-maximize-borderThe maximize button border of the card header
--deckgo-highlight-code-ubuntu-header-button-minimize-backgroundThe minimize button background of the card header @default linear-gradient(#7d7871 0%, #595953 100%)
--deckgo-highlight-code-ubuntu-header-button-minimize-borderThe minimize button border of the card header
--deckgo-highlight-code-ubuntu-header-button-span-displayThe Ubuntu buttons span display @default inherit
--deckgo-highlight-code-ubuntu-header-button-text-shadowThe text-shadow of a button of the card header @default 0px 1px 0px rgba(255, 255, 255, 0.2)
--deckgo-highlight-code-ubuntu-header-button-widthThe width of a button of the card header @default 12px
--deckgo-highlight-code-ubuntu-header-font-familyThe font-family property of the card header @default "Ubuntu"
--deckgo-highlight-code-ubuntu-header-heightThe height property of the card header @default 25px
--deckgo-highlight-code-ubuntu-header-paddingThe padding property of the card header. @default 0 0.5em
--deckgo-highlight-code-ubuntu-header-user-colorThe user's color of the card header. @default #d5d0ce
--deckgo-highlight-code-ubuntu-header-user-font-sizeThe user's font-size of the card header @default 12px
--deckgo-highlight-code-ubuntu-header-user-line-heightThe user's line-height of the card header @default 14px
--deckgo-highlight-code-ubuntu-header-user-marginThe user's margin of the card header @default 0 0 1px 4px
--deckgo-highlight-code-ubuntu-marginThe margin property of the host container @default 16px 0
--deckgo-highlight-code-ubuntu-overflowThe overflow property of the host container @default auto
--deckgo-highlight-code-white-spaceThe attribute white-space of the displayed @default pre-wrap
--deckgo-highlight-code-widthWidth property of the shadowed code block
--deckgo-highlight-code-zoomIf you wish to manually zoom the code @default 1
--deckgo-lowlight-code-line-backgroundThe background of the lines you do not wish to highlight
--deckgo-lowlight-code-line-border-bottomThe border-bottom property of the lines you do not wish to highlight
--deckgo-lowlight-code-line-border-topThe border-top property of the lines you do not wish to highlight
--deckgo-lowlight-code-line-colorThe color of the lines you do not with to highlight
--deckgo-lowlight-code-line-font-weightThe font-weight of the lines you do not wish to highlight
--deckgo-lowlight-code-line-numbers-colorThe color property of the line numbers if not highlighted @default rgba(var(var(--deckgo-highlight-code-token-comment-rgb, 98, 114, 164), 0.32))
--deckgo-lowlight-code-line-opacityThe opacity of the lines you do not wish to highlight @default 0.32

Dependencies

Depends on

Graph

graph TD;
  deckgo-highlight-code --> deckgo-highlight-code-edit
  style deckgo-highlight-code fill:#f9f,stroke:#333,stroke-width:4px

Built with StencilJS