Pages

Tuesday, December 15, 2009

Inserting code to your Webpage or blogger

Well, if you are doing this in live space blog then it is ok. However, if you are trying to insert code snippet to your Blogger (blogspt) then the format given by the plugin in Window Live Writer (WLW) will be incompatible. There will be multiple line spacing in the code snippet appear in the blogger (blogspot) layout.

To solve this, problem one can make use of the Syntax Highlighter integration. What it does it, it link the code you enter to its server and through javascript, it format the code for you.

To do that you first have to edit your blog layout template HTML.
Look for </head> in your HTML Layout Template and insert the following line of code

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


These line simply tell your webpage to look for the javascript in the Syntax Highlighter Website http://alexgorbatchev.com/pub/sh/2.1.364/scripts/



However, this isn’t complete yet, to let your webpage know that the line is a source code snippet, you have to enclose it with



<pre class="brush: cpp">
#### YOUR SOURCE CODE INSERT HERE ####
</pre>


if it is not c++ source code, then you just change it to the source code e.g. “brush: xml” for HTML or XML etc

No comments:

Post a Comment