npm

Bring the best of OSS JavaScript development to your projects with npm Orgs - private packages & team management tools.Learn more »

gitbook-plugin-code-highlighter

1.0.7 • Public • Published

gitbook-plugin-code-highlighter

GitBook plugin to highlight specific lines in code blocks.

Example

Here are a couple of highlighted Python code lines using a yellow background:

The above example was generated from these source lines:

from os import environ
&&&from fabric.api import *
from fabric.context_managers import cd
&&&from fabric.contrib.files import sed

Plugin Installation

  1. Make sure you have GitBook and the gitbook-cli installed.

  2. The default highlight plugin that is built into GitBook must be disabled, because it prevents other plugins from processing code blocks. Here is an example book.json with the highlight plugin disabled and this code-highlighter plugin enabled.

     {
         "author": "Matthew Makai",
         "cover": "cover.jpg",
         "gitbook": "2.x.x",
         "plugins": ["-highlight", "code-highlighter"],
         "title": "The Full Stack Python Guide to Deployments",
         "pdf": {
             "pageNumbers": true,
             "headerTemplate": " ",
             "footerTemplate": " "
         }
     }
    
  3. Run gitbook install to pull down the latest plugin version from NPM.

How To Use After Installation

Within a block code prepend &&& to each line that should be highlighted. Then add a .code-line-highlight property with a background-color to the .css files under the styles/ directory.

For example, your styles/ directory can contain a pdf.css with this line:

.code-line-highlight {background-color: #ffff00;}

That will highlight each selected line in yellow.

For more information on styling, refer to the GitBook docs.

More Information

The &&& mark and the CSS class can be made configurable, but I have not added that feature just yet.

Keywords

none

install

npm i gitbook-plugin-code-highlighter

Downloadsweekly downloads

10

version

1.0.7

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability