Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blogger.com: How to embed formatted code snippet in a blog post?

I have a blog on blogger.com and would like to format my code example in my post.

What do I need to use to format the code snippet in my blog post?

like image 823
mekbib.awoke Avatar asked Feb 14 '19 20:02

mekbib.awoke


People also ask

How do I add a code Snippet to Blogger?

In your Blogger dashboard, click Layout and then click the Add a Gadget link in the sidebar area. Choose the HTML/Javascript gadget from the list and paste your inline code into the widget.

How do you display code snippets on a webpage?

This is quick and easy to do using a tool like: http://htmlencode.net/ Use <pre><code> tags to surround your code. For the <pre> tag you can optionally add class=”line-numbers”. This will add line numbers to your code and these line numbers will not be copied if students copy and paste snippets.


1 Answers

Here is a Blogger.com blog with a tutorial post on how to do it Syntax Highlighting with Blogger Engine Either try using Hilite for converting the code to embedable one or use Gist - this would be the easiest solution.

If by any chance it's outdated solution for your needs then read this: Formatting code snippets for blogging on Blogger

Add syntax highlighter in your template just above the tag:

<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/> 
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'></script> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'></script> 
<script language='javascript'> 
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf';
SyntaxHighlighter.all();
</script>

And then just add the code snippet.

like image 193
richardev Avatar answered Sep 29 '22 22:09

richardev