Created
March 11, 2021 22:06
-
-
Save webarthur/7fe933ef386d4875bc8a373a58ac5159 to your computer and use it in GitHub Desktop.
Load highlight.js asynchronously
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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