Blogger: code highlight in post without changing template ( using highlight.js )

Trabla: Blogger: code highlight in post without changing template ( using highlight.js )


Solving:


We will use highlight.js to hightlight code in this post.
Official Site: https://highlightjs.org/download/

1. Set HTML mode in Blogger post editor

Blogger: code highlight in post without changing template ( using highlight.js )  - tutorial 1


2. Paste following code


<link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/styles/default.min.css" rel="stylesheet"></link>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.1.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>

<pre><code class="js">

//A new variable
var v = "aaa";

//The helloWorld Function :)
function helloWorld(){

        return "Hello World";

}
</code></pre>


Blogger: code highlight in post without changing template ( using highlight.js )  - tutorial 2


3. Save post and click "Preview"  button ( in editor you will not see highlight )


Blogger: code highlight in post without changing template ( using highlight.js )  - tutorial 3


Result:



//A new variable
var v = "aaa";

//The helloWorld Function :)
function helloWorld(){

        return "Hello World";

}


Blogger: code highlight in post without changing template ( using highlight.js )  - tutorial 4



No comments:

Post a Comment