Was this page helpful?

Display syntax highlighting

    Table of contents
    No headers

     The MindTouch syntax extension provides built-in support for highlighting syntax of popular programming languages.  This extension is based on the work done by Alex Gorbatchev on the syntaxhighlighter project. To use it:

    SyntaxHighlighting1.PNG
    Figure 1

    SyntaxHighlighting2.PNG
    Figure 2

    SyntaxHighlighting3.PNG
    Figure 3

    1. Enable the syntax extension using these instructions.
    2. Open the affected page in the editor.
    3. Set Style to Formatted.
       
    4. Enter the content to which you want to apply syntax highlighting.
    5. Select the content, click Transform Content, and choose a language.
    6. Save the page.

     

    Note that it is also possible to use syntax highlighting on file data, rather than page content.  To do this, pass the output of web.text to the syntax extension:

      Output

    To display the formatted contents of an XML file:

    {{ syntax.xml(web.text("http://scripts.mindtouch.com/scratch.xml")) }}

    <extension>
      <title>Scratch Extension</title>
      <label>Scratch</label>
      <copyright>Copyright (c) 2006-2010 MindTouch Inc.</copyright>
      <description>This extension contains functions for embedding Scratch applications.</description>
      <uri.help>http://developer.mindtouch.com/App_Catalog/Scratch</uri.help>
      <uri.logo>http://scripts.mindtouch.com/logos/scratch-logo.png</uri.logo>
    
      <function>
        <name>scratch</name>
        <description>Embed a Scratch application.</description>
        <param name="id" type="str">Application User/ID.</param>
        <param name="width" type="num" optional="true">Application width. (default: 482)</param>
        <param name="height" type="num" optional="true">Application height. (default: 387)</param>
        <return>
          <html xmlns:eval="http://mindtouch.com/2007/dekiscript">
            <body>
              <applet id="ProjectApplet" style="display:block" code="ScratchApplet" codebase="http://scratch.mit.edu/static/misc" archive="ScratchApplet.jar" eval:width="web.size(args.width ?? 482)" eval:height="web.size(args.height ?? 387)">
                <param name="project" eval:value="'../../static/projects/' .. args.id .. '.sb'" />
              </applet>
              <a eval:href="'http://scratch.mit.edu/projects/' .. args.id">Learn more about this project</a>
            </body>
          </html>
        </return>
      </function>
    </extension>

    Was this page helpful?
    Tag page

    Files 3

    FileVersionSizeModified 
    Viewing 5 of 5 comments: view all
    How do you add other features (like collapse) using this method?
    Posted 18:16, 5 May 2008
    Is it possible to use syntax highlighting for a locally attached file?
    Posted 00:44, 20 Mar 2009
    Yes, absolutely. To highlight an attached java file do: {{ syntax.java(web.text(page.files['file-to-show.java'].uri)) }}
    Posted 05:18, 20 Mar 2009
    I'd like to create a highlightning style for other languages, like cobol, SPSS-syntax etc. How can I create a layout file for that, and if it works: how can I share it with others?
    Posted 08:46, 15 Dec 2009
    @maehrus search the forums. others have contributed syntax highlighters. it's pretty simple.
    Posted 09:36, 21 Dec 2009
    Viewing 5 of 5 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by