Skip to content

mattmakai/gitbook-plugin-code-highlighter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

GitBook plugin. Highlight specific lines in code blocks.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published