Home
Categories
Dictionary
Download
Project Details
Changes Log
What Links Here
How To
Syntax
FAQ
License

Syntax highlighting



This article explains how the syntax highlighting in the pre or source elements work.

Supported syntaxes

The built-in supported syntaxes are:
Supported syntaxes
Syntax Name Alternate names
batch files[1]
They are Windows bat files
batch bat
C++ files c++ cpp
C# files csharp c#
C files c C
fortran files fortran -
html files html -
idl declarations idl IDL
JavaScript files jscript js, javascript
JSON files[2]
JSON files are valid JavaScript files, so the syntax for these files is the same
json -
Java files java -
Groovy files[3]
Groovy files are presented by default with the same syntax as Java files, though the syntax can be overriden by syntax packs
groovy -
makefiles make -
php files php -
properties files props properties
Python files python py
SQL files sql SQL
T-SQL files tsql T-SQL
shell scripts[4]
they are Unix or Linux shell scripts
shell bash
XML files xml dtd, DTD, xsd, xsl
SPARQL files sparql -
TeX files tex -
xpath files xpath -
patch files patch -
eiffel files eiffel -
manifest files[5]
it is Java manifest file
manifest -
css files css -
csv files[6]
Uses commas as delimiters
csv -
csv2 files[7]
Uses semi-colons as delimiters
csv2 -
turtle files turtle ttl

To show < or > characters you will need to use their escaped form escapedlt or escapedgt .

Syntaxes alternate names

Some syntaxes have alternate names. For example, the two pre declarations are equivalent:
   name=value
or:
   name=value

Using invisible characters

It is possible to use the "_" character at the start of a line in the "pre" element, which will be replaced by a space. This is the case when there are one or more "_" character followed by a space, before the rest of the line. For example:
   <pre syntax="java">
      public void toto(int i) {
      _  System.out.println(i);
      }
   </pre>
This allows to keep the indentation for programming languages when using formatting in some editors[8]
For example, Netbeans remove the white spaces at the beginning of a line when specifying text in XML, which might not be what we want


By default the "_" character will be replaced by a space for code and shell syntaxes[9]
For example, java, groovy, bat or shell syntaxes among others
. It is possible to set explicitly if "_" characters must be kept or replaced by setting the invisibleChars attribute in the "pre" element. For example:
<pre syntax="java" invisibleChars="false">
   public void toto(int i) {
   _ System.out.println(i);
   }
</pre>

Additional syntaxes packs

The application uses the jeditor library to highlight pre element syntax. It is possible to use additional syntax packs by specifying the preSyntax property in the configuration file.

Examples

On a Java syntax

   <pre syntax="java">
      public void toto(int i) {
      System.out.println(i);
      }
   </pre>

On a Java syntax, with usage of invisible characters

   <pre syntax="java">
      public void toto(int i) {
      _  System.out.println(i);
      }
   </pre>
will have the following result:
   public void toto(int i) {
      System.out.println(i);
   }

On an XML syntax

   <pre syntax="java">
      <parent name="name">
         <child name="child" />
      </parent>
   </pre>
will have the following result:
   <parent name="name">
      <child name="child" />
   </parent>

On a CSS syntax

  <pre syntax="css">
     div.left {
     _  float: left;
     _  display: flex;
     }
  </pre>
will have the following result:
   div.left {
      float: left;
      display: flex;
   }

On a properties file

  <pre syntax="properties">
    name=toto
    position=left
  </pre>
will have the following result:
  name=toto
  position=left

Notes

  1. ^ They are Windows bat files
  2. ^ JSON files are valid JavaScript files, so the syntax for these files is the same
  3. ^ Groovy files are presented by default with the same syntax as Java files, though the syntax can be overriden by syntax packs
  4. ^ they are Unix or Linux shell scripts
  5. ^ it is Java manifest file
  6. ^ Uses commas as delimiters
  7. ^ Uses semi-colons as delimiters
  8. ^ For example, Netbeans remove the white spaces at the beginning of a line when specifying text in XML, which might not be what we want
  9. ^ For example, java, groovy, bat or shell syntaxes among others

See also


Categories: syntax

docJGenerator Copyright (c) 2016-2023 Herve Girod. All rights reserved.