This extension contains functions for highlighting syntax of popular programming languages.  Related Links: Extension Overview, DekiScript Overview, Extension Demos.

Assembly: mindtouch.deki.services
SID: http://services.mindtouch.com/deki/draft/2007/06/syntax

This service requires Deki Wiki 1.8.2 or later.

To enable this extension, follow these steps:

  1. Go to Service management in the Control Panel of your wiki.
  2. Under Add Service, click on Local, and select type Extension.
  3. Enter a description and the extension SID: http://services.mindtouch.com/deki/draft/2007/06/syntax
  4. Add any additional configuration settings that are required by the extension (see below).
  5. Click on add service.

This extension is based on the work done by Alex Gorbatchev on the syntaxhighlighter project.  Refer here for more information on how to embed this extension.

How to use the Syntax extension:

The easiest way to format text using the Syntax extension is to use the Transform menu: create a paragraph using the "formatted" style, paste or write the code you wish to format, then select the appropriate "syntax" transform from the toolbar menu.

Note in some editors the dropdown is not available, in that case you may need to have to apply the transform manually.  Toggle to HTML/Source mode, find the <pre> element preceding the content to format, and change it to <pre class="script" function="syntax.php"> to apply the "syntax.php" transform function.

Once the transform is applied, the formatted paragraph will indicate that its content is dynamically generated.  Save the page.  Once the browser reloads, your content will be formatted with the function you selected.

Functions:

  1. syntax.cpp
  2. syntax.csharp
  3. syntax.css
  4. syntax.delphi
  5. syntax.html
  6. syntax.java
  7. syntax.javascript
  8. syntax.perl
  9. syntax.php
  10. syntax.python
  11. syntax.ruby
  12. syntax.shell
  13. syntax.sql
  14. syntax.vb
  15. syntax.xml

syntax.cpp(code : str, collapse : bool, firstline : num) : xml

Highlight C/C++ syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

    Output

To embed highlighted C/C++:

#include <iostream.h>
main()
{
    cout << "Hello World!" << endl;
    return 0;
}
./SyntaxCpp.JPG

   


syntax.csharp(code : str, collapse : bool, firstline : num) : xml

Highlight C# syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

    Output

To embed highlighted C#:

using System;
class HelloWorld
{
    public static int Main(String[] args)
    {
        Console.WriteLine("Hello, World!");
        return 0;
    }
}
./SyntaxCsharp.JPG

   


syntax.css(code : str, collapse : bool, firstline : num) : xml

Highlight CSS syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

    Output

To embed highlighted CSS:

body:before {
    content: "Hello World!";
}
./SyntaxCss.JPG

   


syntax.delphi(code : str, collapse : bool, firstline : num) : xml

Highlight Delphi syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

    Output

To embed highlighted Delphi:

Program Hello_World;
{$APPTYPE CONSOLE}
Begin
  WriteLn('Hello World!');
End.
./SyntaxDelphi.JPG

   


syntax.html(code : str, collapse : bool, firstline : num) : xml

Highlight HTML syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

    Output

To embed highlighted HTML:

<HTML>
<HEAD>
<TITLE>Hello World!</TITLE>
</HEAD>
<BODY>
Hello World!
</BODY>
</HTML>
./SyntaxHtml.JPG

   


syntax.java(code : str, collapse : bool, firstline : num) : xml

Highlight Java syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

    Outpu

To embed highlighted Java:

class HelloWorld {
  static public void main( String args[] ) {
    System.out.println( "Hello World!" );
  }
}
./SyntaxJava.JPG

   


syntax.javascript(code : str, collapse : bool, firstline : num) : xml

Highlight JavaScript syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

    Outpu

To embed highlighted JavaScript:

function Hello () {
  alert("Hello World!");
}
./SyntaxJavaScript.JPG

   


syntax.perl(code : str, collapse : bool, firstline : num) : xml

Highlight Perl syntax. (New in 1.8.3)

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

   


syntax.php(code : str, collapse : bool, firstline : num) : xml

Highlight PHP syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

    Outpu

To embed highlighted PHP:

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

   


syntax.python(code : str, collapse : bool, firstline : num) : xml

Highlight Python syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

    Outpu

To embed highlighted Python:

print "Hello World!"
./SyntaxPython.JPG

   


syntax.ruby(code : str, collapse : bool, firstline : num) : xml

Highlight Ruby syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

     Outpu

To embed highlighted Ruby:

puts "Hello World!"
./SyntaxRuby.JPG

    


syntax.shell(code : str, collapse : bool, firstline : num) : xml

Highlight shell script syntax. (New in 1.8.3)

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

   


syntax.sql(code : str, collapse : bool, firstline : num) : xml

Highlight SQL syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

    Outpu

To embed highlighted SQL:

SELECT 'Hello World!';
./SyntaxSql.JPG

   


syntax.vb(code : str, collapse : bool, firstline : num) : xml

Highlight Visual Basic syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

    Outpu

To embed highlighted Visual Basic:

Private Sub Form_Load()
Print "Hello World!"
End Sub
./SyntaxVb.JPG

   


syntax.xml(code : str, collapse : bool, firstline : num) : xml

Highlight XML syntax.

Parameters:

Name Type Description
code str Source code to highlight.
collapse bool Optional.  Collapse code view (default: false)
firstline num Optional.  First line number (default: 1)

Samples:

    Outpu

To embed highlighted XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="HelloWorld.xsl" ?>
<text><string>Hello World!</string></text>
./SyntaxXml.JPG

  

Tag page
Viewing 2 of 2 comments: view all
Is it just me or do the examples make no sense? The examples just show the code you want to highlight but not in context of the actual extension. I still have little idea how to use this extension.
Posted 23:11, 30 Apr 2008
The samples are setup so that you can copy and paste the example block into the editor. I will be adding a more explicit FAQ at http://wiki.opengarden.org/index.php?title=Deki_Wiki/FAQ/Page_Management/How_do_I...Enable_syntax_highlighting%3F. edited 00:19, 1 May 2008
Posted 00:19, 1 May 2008
Viewing 2 of 2 comments: view all
You must login to post a comment.