How to use the initHighlightingOnLoad function from highlight.js

Find comprehensive JavaScript highlight.js.initHighlightingOnLoad code examples handpicked from public code repositorys.

90
91
92
93
94
95
96
97
98
99
<script type="text/javascript">
  hljs.tabReplace = '    '; // 4 spaces
  // ... or
  hljs.tabReplace = '<span class="indent">\t</span>';

  hljs.initHighlightingOnLoad();
</script>
```

## Custom initialization
fork icon16
star icon19
watch icon31

5
6
7
8
9
10
11
12
13
14
15
// This function will run for every page once loaded (script is deffered)
const common = () => {
  // Highlight.js
  // Highlight source code snippets
  hljs.configure({ languages: [] }); // Do not try to guess the language
  hljs.initHighlightingOnLoad(); // Highlight code


  // Lozad
  // Lazy load images (when they enter the viewport)
  window.observer = lozad();
fork icon2
star icon4
watch icon0

9
10
11
12
13
14
15
16
17
18
19
20
21
var renderer = new marked.Renderer()




if(typeof window != 'undefined'){
    window.onload=function(){
        hljs.initHighlightingOnLoad()
    }
}


renderer.code = function(code, lang) {
fork icon0
star icon1
watch icon2

46
47
48
49
50
51
52
53
54
      transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none

      // Optional libraries used to extend on reveal.js
      dependencies: [
          { src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } },
          { src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
      ]
  });
}
fork icon0
star icon1
watch icon2

+ 3 other calls in file