highlight.js

How to add highlight.js to your Doks website.

On this page

1. Enable

highlight.js support is switched on per default.

Like Chroma — the Hugo default code highlighter — better? Deactivate highlight.js support by setting highLight = false in ./config/_default/params.toml.

2. Pick style

Use the default Doks style, or use one of the other available higlight.js themes.

Example

If you would like to use the Dracula style, in ./assets/scss/app.scss uncomment the default doks style, and add the Dracula style, like so:

  1. /** Import highlight.js */
  2. @import "highlight.js/scss/dracula";
  3. ..
  4. // @import "components/doks";

3. Configure

Customize Doks’ default configuration (if needed) in ./assets/js/highlight.js:

  1. import hljs from 'highlight.js/lib/core';
  2. import javascript from 'highlight.js/lib/languages/javascript';
  3. import json from 'highlight.js/lib/languages/json';
  4. import bash from 'highlight.js/lib/languages/bash';
  5. import htmlbars from 'highlight.js/lib/languages/htmlbars';
  6. import ini from 'highlight.js/lib/languages/ini';
  7. import yaml from 'highlight.js/lib/languages/yaml';
  8. import markdown from 'highlight.js/lib/languages/markdown';
  9. hljs.registerLanguage('javascript', javascript);
  10. hljs.registerLanguage('json', json);
  11. hljs.registerLanguage('bash', bash);
  12. hljs.registerLanguage('html', htmlbars);
  13. hljs.registerLanguage('ini', ini);
  14. hljs.registerLanguage('toml', ini);
  15. hljs.registerLanguage('yaml', yaml);
  16. hljs.registerLanguage('md', markdown);
  17. document.addEventListener('DOMContentLoaded', () => {
  18. document.querySelectorAll('pre code').forEach((block) => {
  19. hljs.highlightBlock(block);
  20. });
  21. });

Example

  1. // Default Doks style
  2. [
  3. {
  4. "title": "apples",
  5. "count": [12000, 20000],
  6. "description": {"text": "...", "sensitive": false}
  7. },
  8. {
  9. "title": "oranges",
  10. "count": [17500, null],
  11. "description": {"text": "...", "sensitive": false}
  12. }
  13. ]

Resources