javascriptsyntax-highlightinggitbook

How to use Syntax Highlighting GitBook


I'm new to GitBook and I am trying to make the syntax highlight work as expected for some JavaScript lines of code.


some javascript lines without colour


I noticed that there is a plugin store in the editor. I enabled a plugin called highlight but it's not doing it's job.

I searched in the documentation for this, but I couldn't find anything related.

This book has the syntax highlighting enabled and working:
https://gitbookio.gitbooks.io/javascript/content/basics/comments.html

book.json

{
    "plugins": [
        "highlight"
    ],
    "pluginsConfig": {}
}

How can I do the same?


Solution

  • If you are writing GitBook pages in Markdown, you can highlight your code like below:

    ```javascript
    var foo = function(num) {
        return num + num;
    }
    ```
    

    Where 'javascript' can be replaced with other languages, such as 'python', 'java', 'c' etc.