Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Adds stylish cards and syntax highlighting to code blocks in markdown files

License

NotificationsYou must be signed in to change notification settings

deckgo/gatsby-remark-highlight-code

Repository files navigation

Adds stylish cards and syntax highlighting to code blocks in markdown files of yourGatsby website.

The Web Component behind this feature was created for the web editor for presentationsDeckDeckGo.

It is implemented withStencil and usePrism.js under the hood.

The inspiration for the design of the "Macish" cards comes from the amazingcarbon, a tool to create and share beautiful images of your source code, and for the "Ubuntu-ish" from thearticle ofCody Pearce.

Design

1. Carbon

Syntax highlighting code block as Carbon card

Multiple theming options.

Syntax highlighting code block as Carbon card

2. Ubuntu

Syntax highlighting code block as Ubuntu card

3. None

No predefined cards but stylable with multipleCSS variables.

Syntax highlighting code block

Table of contents

Install

npm install --save gatsby-transformer-remark gatsby-remark-highlight-code @deckdeckgo/highlight-code

How to use

In order to use this plugin, it should be firstconfigured and thenloaded at runtime.

Configure

If you are using "gatsby-transformer-remark", you can add "gatsby-remark-highlight-code" like this:

// In your gatsby-config.jsplugins:[{resolve:`gatsby-transformer-remark`,options:{plugins:[{resolve:`gatsby-remark-highlight-code`,},],},},];

If you are using "gatsby-plugin-mdx", you can add "gatsby-remark-highlight-code" like this:

// In your gatsby-config.jsplugins:[{resolve:`gatsby-plugin-mdx`,options:{extensions:[".mdx",".md"],gatsbyRemarkPlugins:[{resolve:`gatsby-remark-highlight-code`,},],},},];

Load the component

Load the@deckdeckgo/highlight-code once in one of your pages or components.

For example add the following in the main file of your website, in yourindex.js, or in yourlayout.js, in the template of your blog or simply load it where you need it.

import{defineCustomElementsasdeckDeckGoHighlightElement}from"@deckdeckgo/highlight-code/dist/loader";deckDeckGoHighlightElement();

Plugin Options

propertytypedefault
terminalcarbon,ubuntu ornonecarbon
theme3024-night ,a11y-dark ,blackboard ,base16-dark ,base16-light ,cobalt ,dracula ,duotone ,hopscotch ,lucario ,material ,monokai ,night-owl ,nord ,oceanic-next ,one-light ,one-dark ,panda ,paraiso ,seti ,shades-of-purple ,solarized-dark ,solarized-light ,synthwave ,twilight ,verminal ,vscode ,yeti ,zenburndracula
editablebooleanfalse
lineNumbersbooleanfalse

Language

This plugin supports all languages supported byPrism.js. Nothing particular needs to be specified because the component@deckdeckgo/highlight-code will load them automatically at runtime.

Styling

Code blocks are displayed in stylish cards but the behavior could be customized.

Terminal

Per default, code blocks are going to be displayed incarbon ("Macish like") container.

It is also possible to useubuntu (an Ubuntu-like container) ornone (no window container).

Such settings can be provided in the configuration of the plugin.

// In your gatsby-config.jsplugins:[{resolve:`gatsby-transformer-remark`,options:{plugins:[{resolve:`gatsby-remark-highlight-code`,options:{terminal:"ubuntu",},},],},},];

Theme

The terminalcarbon can be themed with a wide range of predefined themes.

These can be tried out in the@deckdeckgo/highlight-code documentation and applied as following:

// In your gatsby-config.jsplugins:[{resolve:`gatsby-transformer-remark`,options:{plugins:[{resolve:`gatsby-remark-highlight-code`,options:{terminal:"carbon",theme:"blackboard",},},],},},];

Variables

See the@deckdeckgo/highlight-code documentation for the list of CSS4 styling variables.

Lines highlighting

Single or multiple lines of code can be highlighted.

Highlight lines

The Markdown syntax is the following: next to the specification of the language, between brackets{}, the lines should be provided in a comma separated list. A single line can be provided (for exampledart{1}) or multiple one, from and to being separated with a dash (for examplejavascript{3-6}). Both single or multiple lines can be mixed (for exampletypescript{2, 3-4, 7, 8-15}).

Animation between the selected highlighted groups can be triggered with the help of methods (see component@deckdeckgo/highlight-code documentation for details).

Showcase

I (David here) use this plugin in the blog of my personal websitedaviddalbusco.com.

License

MIT ©David Dal Busco andNicolas Mattia

About

Adds stylish cards and syntax highlighting to code blocks in markdown files

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

    Packages

    No packages published

    Contributors9


    [8]ページ先頭

    ©2009-2025 Movatter.jp