Posting source code

From NMR Wiki

Jump to: navigation, search

Contents

Introduction

You can post snippets of programming code and scripts using <source> tag (GeSHi extension). Syntax of the programming language will be highlighted for better readability.

Share your scripts and programming tricks!!!

A real life example is here. (it's an extension script for Sparky)

Usage

<source lang="PROGRAMMING_LANGUAGE_NAME">... code ...</source>

Supported languages

These are the languages known by GeSHi that can be used in the lang parameter:

  • actionscript
  • ada
  • apache
  • applescript
  • asm
  • asp
  • autoit
  • bash
  • blitzbasic
  • bnf
  • c
  • caddcl
  • cadlisp
  • cfdg
  • cfm
  • cpp-qt
  • cpp
  • csharp
  • css-gen.cfg
  • css
  • c_mac
  • d
  • delphi
  • diff
  • div
  • dos
  • eiffel
  • fortran
  • freebasic
  • gml
  • groovy
  • html4strict
  • idl
  • ini
  • inno
  • io
  • java
  • java5
  • javascript
  • latex
  • lisp
  • lua
  • matlab
  • mirc
  • mpasm
  • mysql
  • nsis
  • objc
  • ocaml-brief
  • ocaml
  • oobas
  • oracle8
  • pascal
  • perl
  • php-brief
  • php
  • plsql
  • python
  • qbasic
  • reg
  • robots
  • ruby
  • sas
  • scheme
  • sdlbasic
  • smalltalk
  • smarty
  • sql
  • tcl
  • text
  • thinbasic
  • tsql
  • vb
  • vbnet
  • vhdl
  • visualfoxpro
  • winbatch
  • xml
  • z80

Examples

C#

<source lang="csharp">
// Hello World in Microsoft C# ("C-Sharp").

using System;

class HelloWorld
{
    public static int Main(String[] args)
    {
        Console.WriteLine("Hello, World!");
        return 0;
    }
}
</source>

Results in:

// Hello World in Microsoft C# ("C-Sharp").
 
using System;
 
class HelloWorld
{
    public static int Main(String[] args)
    {
        Console.WriteLine("Hello, World!");
        return 0;
    }
}

PHP

<source lang="php">
<?php
  // Hello World in PHP
  echo 'Hello World!';
?>
</source>

Results in:

<?php
  // Hello World in PHP
  echo 'Hello World!';
?>

Python

<source lang="python">
def main():
    print "Hello World!"

if __name__ == '__main__':
    main()
</source>

Results in:

def main():
    print "Hello World!"
 
if __name__ == '__main__':
    main()

Fortran

bugs:

  • comments for fortran77 do not work (line starts with C)
<source lang="fortran">
C *
C *testing this srcipt
C *
c * comments for fortran77 do not work!

hello = "Hello World!"

if hello .eq. 'test' then
 !do nothing
else
 !do something
 x = 1
endif
</source>

Results in:

C *
C *testing this srcipt
C *
c * comments for fortran77 do not work!
 
hello = "Hello World!"
 
if hello .eq. 'test' then
 !do nothing
else
 !do something
 x = 1
endif
Personal tools