Code Block in Blogger
Inserting code block in Blogger is basically to insert your code between HTML code tags. But it is very raw and without syntax highlighting. To get the code block with syntax highlighting and styling, you can use highlight.js. It is also on GitHub @ highlight.js GitHub.
On the highlight.js GitHub pages, copy and paste on the top of post the snippet of HTML and replace respective library link with the links copied from chnjs.com/libraries/highlight.js as follow.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
Then in HTML View of Blogger's composing post/page, insert your codes between <pre><code class="language-name> and </code></pre> and replace name with the name of the language. Eg.
<pre><code class="language-sh">your codes is here...</code></pre>
This way is much better and cleaner than editing Blogger Theme's HTML Codes. See the following example.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github-dark.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<span style="font-size: large;">
<p>
Example of paragraph. <b>this is bold font</b> and <i>this is italic font</i>.
</p>
</span>
<pre><code class="language-sh">#!/bin/dash
# insert code here ...
</code></pre>
Comments
Post a Comment