Skip to content

Instantly share code, notes, and snippets.

@webarthur
Created March 11, 2021 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webarthur/7fe933ef386d4875bc8a373a58ac5159 to your computer and use it in GitHub Desktop.
Save webarthur/7fe933ef386d4875bc8a373a58ac5159 to your computer and use it in GitHub Desktop.
Load highlight.js asynchronously
<script async src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"></script>
<script>
const awaitFor = function (cond, cb, timeout = 100) {
!cond() ? setTimeout(() => awaitFor(cond, cb, timeout), timeout) : cb()
}
awaitFor(() => typeof hljs !== 'undefined', function () {
const blocks = document.querySelectorAll('pre code')
blocks.forEach(hljs.highlightBlock)
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment