0

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?

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

2

I did my research and I found out how to do this.

I tried another plugin called Ace. This plugin worked, here is my book.json

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

And I needed to nest the block of code with a basic syntax for JavaScript.

Input.

## The Arrow function
Now this should be syntax highlighted
In ES5

{%ace edit=false, lang='javascript', check=false, theme="tomorrow" %}
var myFunction = function(num) {  
    return num + num;
};
{%endace%}

In ES6

{%ace edit=false, lang='javascript', check=false, theme="tomorrow" %}
let myFunction = (num) => num + num;
{%endace%}

Output.

code highlighted

This is working just fine!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.