Skip to main content

Display programming code in your blog/website

When you make some programming code in any IDE (Integrated Development Environment), they are formatted to be read easily. But when you post them on a blog/website, everyone only see them in plain text formatting. It's inconvenient. SyntaxHighlighter, a JavaScript module, will help you to solve this problem.


  • Open your blog/website html template, insert below tag below code:






      • <script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js">
        <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/>
        <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/>
        <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/>
        <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
        <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
        <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/>
        <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
        <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
        <script language="javascript">
        SyntaxHighlighter.config.bloggerMode = false;
        SyntaxHighlighter.all();
        </script>

        Note: in code line 2, bloggerMode = true if you use SyntaxHighlighter for your blogger blog.


    • Then, every time you want to post some programming code, on html editor, you just need to surround them with:



<pre class="brush:language">your code here</pre>

or
<script type="syntaxhighlighter" class="brush:language "><![CDATA[your code here]]></script>


  • Some brush for your code: 

    • C#: c-sharp, csharp

    • C++: cpp, c

    • JavaScript: js, jscript, javascript

    • Java: java

    • PHP: php

    • PowerShell: ps, powershell

    • SQL: sql

    • HTML/XML: xml, xhtml, xslt, html, xhtml

    • More here





Here is an example:




[html]<pre class="brush:csharp;">for(int i = 0; i &lt; 100; i++)
{
MessageBox.show("Hello World!");
}</pre>[/html]

 
=> Result:


for(int i = 0; i &lt; 100; i++)
{
MessageBox.show("Hello World!");
}

 


With succeed!

Comments

Popular posts from this blog

Turn off AutoPlay on Windows

On Windows, when you insert an USB or a CD/DVD into your computer, they are usually opened automatically. So the computer maybe infected autorun virus. To avoid that, you should turn off AutoPlay function.

Create Wordpress page template

When creating a new page in Wordpress, we usually have a choice for the page template. It's call Default template . However, we sometimes need to make a new page with a new appearance. Then another page template is needed. Instead of downloading a shared page template from internet, we can create a new page template by below instructions.