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.

Vendor
MindTouch
Type Script
Categories Developers
Requires MindTouch Deki 1.8.3 or later
Status Stable
License Free/Open Source
Manifest http://scripts.mindtouch.com/syntax.xml

 

Table of Contents

Description

This extension contains functions for highlighting syntax of popular programming languages.

See also How to add a script, Using the Extension Dialog, Learn about DekiScript, Extensions Directory.


Configuration

The following configuration settings are required to run this script (unless shown as optional).

NameTypeDescription
resources-uriuriBase uri for syntax service javascript files (default: http://scripts.mindtouch.com/res/syntax/)


Functions

syntax.cpp(code, collapse, firstline) : xml

Highlight C/C++ syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.CSharp(code, collapse, firstline) : xml

Highlight C# syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Css(code, collapse, firstline) : xml

Highlight CSS syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.DekiScript(code, collapse, firstline) : xml

Highlight DekiScript syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Delphi(code, collapse, firstline) : xml

Highlight Delphi syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Html(code, collapse, firstline) : xml

Highlight HTML syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Java(code, collapse, firstline) : xml

Highlight Java syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.JavaScript(code, collapse, firstline) : xml

Highlight JavaScript syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Perl(code, collapse, firstline) : xml

Highlight Perl syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Php(code, collapse, firstline) : xml

Highlight PHP syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Powershell(code, collapse, firstline) : xml

Highlight Powershell syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Python(code, collapse, firstline) : xml

Highlight Python syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Ruby(code, collapse, firstline) : xml

Highlight Ruby syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Shell(code, collapse, firstline) : xml

Highlight bash/sh/ksh syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Sql(code, collapse, firstline) : xml

Highlight SQL syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Text(code, collapse, firstline) : xml

Show plain text

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Vb(code, collapse, firstline) : xml

Highlight Visual Basic syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


syntax.Xml(code, collapse, firstline) : xml

Highlight XML syntax

Parameters:

NameTypeDescription
codestrsource code to highlight
collapsebool(optional) collapse code view (default: false)
firstlinenum(optional) first line number (default: 1)


Script Source

<extension>
  <title>MindTouch Syntax Extension</title>
  <label>Syntax</label>
  <copyright>Copyright (c) 2006-2009 MindTouch, Inc.</copyright>
  <description>This extension contains functions for highlighting syntax of popular programming languages.</description>
  <uri.help>http://wiki.developer.mindtouch.com/MindTouch_Deki/Extensions/Syntax</uri.help>
  <namespace>syntax</namespace>
  <config>
    <param name="resources-uri" type="uri">Base uri for syntax service javascript files (default: http://scripts.mindtouch.com/res/syntax/)</param>
  </config>

  <function transform="pre">
    <name>cpp</name>
    <description>Highlight C/C++ syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushCpp.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'c' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>CSharp</name>
    <description>Highlight C# syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushCSharp.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'c#' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Css</name>
    <description>Highlight CSS syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushCss.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'css' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Delphi</name>
    <description>Highlight Delphi syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushDelphi.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'delphi' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Java</name>
    <description>Highlight Java syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushJava.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'java' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>JavaScript</name>
    <description>Highlight JavaScript syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushJScript.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'js' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Perl</name>
    <description>Highlight Perl syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushPerl.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'perl' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Php</name>
    <description>Highlight PHP syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushPhp.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'php' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Python</name>
    <description>Highlight Python syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushPython.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'python' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Ruby</name>
    <description>Highlight Ruby syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushRuby.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'ruby' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Shell</name>
    <description>Highlight bash/sh/ksh syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushShell.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'bash' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Sql</name>
    <description>Highlight SQL syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushSql.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'sql' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Vb</name>
    <description>Highlight Visual Basic syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushVb.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'vb' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Xml</name>
    <description>Highlight XML syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushXml.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'xml' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Html</name>
    <description>Highlight HTML syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushXml.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'xml' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>DekiScript</name>
    <description>Highlight DekiScript syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushDekiscript.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'dekiscript' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Powershell</name>
    <description>Highlight Powershell syntax</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushPowershell.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'powershell' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
  <function transform="pre">
    <name>Text</name>
    <description>Show plain text</description>
    <param name="code" type="str">source code to highlight</param>
    <param name="collapse" type="bool" optional="true">collapse code view (default: false)</param>
    <param name="firstline" type="num" optional="true">first line number (default: 1)</param>
    <return>
      <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
        <head block="var baseUri = config['resources-uri'] ?? 'http://scripts.mindtouch.com/res/syntax'">
              <link type="text/css" rel="stylesheet" eval:href="uri.appendpath(baseUri, 'SyntaxHighlighter.css')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shCore.js')" />
              <script type="text/javascript" eval:src="uri.appendpath(baseUri, 'shBrushNone.js')" />
        </head>
        <body>
          <pre name="code" eval:class="'none' .. (args.collapse == 'true' ? ':collapse' : '') .. (args.firstline ? ':firstline[' .. args.firstline .. ']' : '');"><eval:expr value="args.code"/></pre>
        </body>
        <tail>
          <script type="text/javascript">dp.SyntaxHighlighter.HighlightAll('code');</script>
        </tail>
      </html>
    </return>
  </function>
</extension>

 


Samples

    Output

To embed highlighted C/C++:

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

To embed highlighted C#:

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

To embed highlighted CSS:

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

To embed highlighted Delphi:

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

To embed highlighted HTML:

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

To embed highlighted Java:

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

To embed highlighted JavaScript:

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

To embed highlighted PHP:

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

To embed highlighted Python:

print "Hello World!"
./SyntaxPython.JPG

To embed highlighted Ruby:

puts "Hello World!"
./SyntaxRuby.JPG

To embed highlighted SQL:

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

To embed highlighted Visual Basic:

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

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 5 of 5 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
Why does an extra empty span block get created after each php comment line? This pushes the code down an extra line and throws off the spacing. Where can I find a fix for this? edited 18:56, 23 Oct 2008
Posted 18:55, 23 Oct 2008
Hi!

When I break a line with CR + LF the highliter doesn't work. For example in:

{{ syntax.Delphi{code: "

Program Hello_World;

{$APPTYPE CONSOLE}

Begin

WriteLn('Hello World!');

End. "} }}



What is the correct way to add line breaks in the source code?

Thank you!

--
Jeferson Oliveira
Brazil
Posted 15:07, 25 Jan 2009
The correct way to use this extension is to create a "formatted" (i.e. <pre>) section, paste in your code (with newlines, tabs, etc.), then select the desired syntax highlighter from the "transformations" menu in the editor.
Posted 16:19, 25 Jan 2009
Viewing 5 of 5 comments: view all
You must login to post a comment.