Tuesday, August 03, 2021

Syntax Highlighting

I decided to use highlight js for syntax highlighting. For theme, I'm using the Stack Overflow light theme. Here's what I had to include in my template:
<link href='//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.1.0/styles/stackoverflow-light.min.css' rel='stylesheet'/>

<script src='//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.1.0/highlight.min.js'/>

<script>hljs.highlightAll();</script>

In each post, you use a pre and a code tag like this:
<pre>
<code class="language-js">
    let myPromise = new Promise( (resolve, reject) => { 
        setTimeout(()=>resolve('my results'),1000) 
    });

    myPromise.then(result => console.log(result));
</code>
</pre>

Post a Comment

Note: Only a member of this blog may post a comment.