This is my third day, i.e. roughly more than 2 hours, playing with Blogger. So, this post reflects my minimal knowledge of the system. If you have better solutions, please drop me a comment below. So far, I really like Blogger for its simplicity. However, I didn't find a nice and efficient way to put code snippets into my blog posts. A quick google search reveals that many people have struggled with this problem before. The most popular solution I found is SyntaxHighlighter, written by Alex Gorbatchev.
Use SyntaxHighlighter
Just in case you're not familiar with it, follow the steps below:
- Use this generator to generate the links to css and javascript files. The generator lets you choose the theme, and the languages that you like to support. Among the generated files,
shCore.*
andshTheme*.css
are required, other filesshBrush*.js
are based on your need. - Copy the links generated in step 1 and paste into your Blogger's template file, right above
</head>
tag. - Save your template.
- In your posts, wrap your code snippets inside the tags:
<pre class="brush: language-name"> </pre>
It's a very nice tool. However, I don't like the question mark appears on every of my code snippets, which links to a site to ask to support the developer. It's a nice thing to do but I feel it's too invasive. The margin, padding is also not as I want. I will have to add some css to customize it the way I want.
Another popular suggestion is using gist
.
Use gist
- Go to gist on github or a similar git-based SVM site
- Paste your code there and generate a
gist
- Then copy the embeded url and paste to your posts
The result looks very good with syntax highlighted. You may have to add your custom css to make the background fit your theme. However, I feel it adds a lot of overhead switching to github to generate the code for every snippet. This solution also helps keep your code clean because every snippet is just one embeded url. However, it has its own disadvantage. If you need to make some quick update to your snippets, it's not clear which one is which and you have to go to gist for any minor update.
Another similar solution is to use hilite.me. However, besides the overhead of switching context, the code generated by this tool is very long because of inline css.
Roll my own solution
After trying all existing solutions that I found, I realize that, for my posts, syntax highlight is not important. I usually post very small code snippet. If I need to go longer, I'd rather link to github. I only want to make the code snippets standout from the remaining text. So, I made some quick custom css to add to Blogger template. Here it is:
pre code {
display: block;
overflow: scroll;
-webkit-overflow-scrolling: touch;
padding: 0 0.5em 1em;
border-radius: 0.5em;
background-color: #1b2426;
}
It's not a perfect solution. It might not even work as expected on all browsers. However, it meets my needs and small enough to maintain and update in the future.
How to modify your blog see below link
ReplyDeletehttp://learnopenerp.blogspot.com/search/label/Blogger
Thanks for sharing great post.
ReplyDeletejava training in Bangalore
Nice Post!!!
ReplyDeleteEasy Digital Downloads Extensions
Some us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage
ReplyDeletecontribution from other ones on this subject while our own child is truly discovering a great deal.
Have fun with the remaining portion of the year.
Selenium training in bangalore
Selenium training in Chennai
Selenium training in Bangalore
Selenium training in Pune
Selenium Online training
The article is so informative. This is more helpful for our
ReplyDeleteLearn best software testing online certification course class in chennai with placement
Best selenium testing online course training in chennai
Best online software testing training course institute in chennai with placement
Thanks for sharing.
Thanks for sharing the valuable information.
ReplyDeleteNodeJs Online Training
NodeJs Training in Hyderabad
NodeJs Training in Ameerpet
wow great Article, the details you have provided are much clear, easy to understand, if you post some more Article, it will be very much useful for me.
ReplyDeletethanks for your information really good and very nice web design company in velachery
Thank for 'pre' solution, may i implement your code in https://thevanjul.blogspot.com/.
ReplyDeleteWonderful thanks for sharing an amazing idea. keep it...
ReplyDeleteGet Best SAP HR HCM Training in Bangalore from Real Time Industry Experts with 100% Placement Assistance in MNC Companies. Book your Free Demo with Softgen Infotech.
https://www.sagapatra.in/2020/04/adding-code-snippet-in-blogger-post.html
ReplyDeleteThanks for informations salam blogger indonesia
ReplyDelete