Skip to content

Instantly share code, notes, and snippets.

@crvdgc
Created May 6, 2018 08:22
Show Gist options
  • Save crvdgc/d7cc45890efcd339407bf5577433ae9d to your computer and use it in GitHub Desktop.
Save crvdgc/d7cc45890efcd339407bf5577433ae9d to your computer and use it in GitHub Desktop.
highlightjs add language class to all code blocks
<!-- if you are using sublime, uncomment to get a snippet
<snippet>
<content><![CDATA[
-->
<link rel="stylesheet" href="PATH_TO_YOUR_CSS\highlight\styles\github.css">
<script src=PATH_TO_YOUR_JS\highlight\highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();
let addLangClass = function () {
document.getElementByTagName("code").classList.add("${1:language}");
}
if(window.attachEvent) {
window.attachEvent('onload', addLangClass);
} else {
if(window.onload) {
let curronload = window.onload;
let newonload = function(evt) {
curronload(evt);
addLangClass();
};
window.onload = newonload;
} else {
window.onload = addLangClass;
}
}
</script>
<!-- if you are using sublime, uncomment the following to get a snippet
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>highlight</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->
</snippet>
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment