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

Fix network printer error 0x0000709

When printing in the network, sometimes you see the error "Operation could not be completed (error 0x00000709). Double click the printer name and make sure that the printer is connected to the network".  Here we show how to fix the error: Open Windows Control Panel Open Credential Manager Choose Windows Credentials Click Add a Windows credential Internet or network address: input the computer name which share the printer User name: input "guest" Password: leave it blank Then click OK and reconnect the shared printer Do not need: uninstall Windows updates; change Windows registry... This maybe applied for error: 0x00000005, 0x0000011b... Watch the step by step video on here: