syntax_highlighting

Syntax highlighting

Code Blocks

You can include code blocks into your documents by either indenting them by at least two spaces (like used for the previous examples) or by using the tags <code> or <file>.

 This is text is indented by two spaces.

This is preformatted code all spaces are preserved: like              <-this
This is pretty much the same, but you could use it to show that you quoted a file.

Those blocks were created by this source:

   This is text is indented by two spaces.
 
 This is preformatted code all spaces are preserved: like              <-this
 
 
 This is pretty much the same, but you could use it to show that you quoted a file.
 

Syntax Highlighting

DokuWiki can highlight sourcecode, which makes it easier to read. It uses the GeSHi Generic Syntax Highlighter – so any language supported by GeSHi is supported. The syntax uses the same code and file blocks described in the previous section, but this time the name of the language syntax to be highlighted is included inside the tag, e.g. <code java> or <file java>.

/**
 * The HelloWorldApp class implements an application that
 * simply displays "Hello World!" to the standard output.
 */
class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); //Display the string.
    }
}

The following language strings are currently recognized: //4cs 6502acme 6502kickass 6502tasm 68000devpac abap actionscript3 actionscript ada aimms algol68 apache applescript apt_sources arm asm asp asymptote autoconf autohotkey autoit avisynth awk bascomavr bash basic4gl batch bf biblatex bibtex blitzbasic bnf boo caddcl cadlisp ceylon cfdg cfm chaiscript chapel cil c_loadrunner clojure c_mac cmake cobol coffeescript c cpp cpp-qt cpp-winapi csharp css cuesheet c_winapi dart dcl dcpu16 dcs delphi diff div dos dot d ecmascript eiffel email epc e erlang euphoria ezt f1 falcon fo fortran freebasic freeswitch fsharp gambas gdb genero genie gettext glsl gml gnuplot go groovy gwbasic haskell haxe hicest hq9plus html html4strict html5 icon idl ini inno intercal io ispfpanel java5 java javascript jcl j jquery julia kixtart klonec klonecpp kotlin latex lb ldif lisp llvm locobasic logtalk lolcode lotusformulas lotusscript lscript lsl2 lua m68k magiksf make mapbasic mathematica matlab mercury metapost mirc mk-61 mmix modula2 modula3 mpasm mxml mysql nagios netrexx newlisp nginx nimrod nsis oberon2 objc objeck ocaml-brief ocaml octave oobas oorexx oracle11 oracle8 oxygene oz parasail parigp pascal pcre perl6 perl per pf phix php-brief php pic16 pike pixelbender pli plsql postgresql postscript povray powerbuilder powershell proftpd progress prolog properties providex purebasic pycon pys60 python qbasic qml q racket rails rbs rebol reg rexx robots rpmspec rsplus ruby rust sas sass scala scheme scilab scl sdlbasic smalltalk smarty spark sparql sql standardml stonescript swift systemverilog tclegg tcl teraterm texgraph text thinbasic tsql twig typoscript unicon upc urbi uscript vala vbnet vb vbscript vedit verilog vhdl vim visualfoxpro visualprolog whitespace whois winbatch xbasic xml xojo xorg_conf xpp yaml z80 zxbasic//

There are additional advanced options available for syntax highlighting, such as highlighting lines or adding line numbers.

Downloadable Code Blocks

When you use the <code> or <file> syntax as above, you might want to make the shown code available for download as well. You can do this by specifying a file name after language code like this:

<file php myexample.php>
<?php echo "hello world!"; ?>
</file>
myexample.php
<?php echo "hello world!"; ?>

If you don't want any highlighting but want a downloadable file, specify a dash (-) as the language code: <code - myfile.foo>.

Syntax Highlighting

DokuWiki includes support for code syntax highlighting as described at the syntax page.

Starting with DokuWiki release “Greebo” some additional GeShi options for syntax highlighting are supported:

 * Enable line numbers
 * Start line numbers at line **n**
 * Highlight certain lines extra

All options are set by adding some key-value pairs to the standard code-tag syntax. The following examples explain their usage.

Examples

The following code enables line numbers:

 
 var de = function() {
 	return (typeof(window.de) == 'object') ? window.de : {};
 }();
 

This is the result:

  1. var de = function() {
  2. return (typeof(window.de) == 'object') ? window.de : {};
  3. }();

The next example additionally highlights one line:

 
 var de = function() {
 	return (typeof(window.de) == 'object') ? window.de : {};
 }();
 

This is the result:

  1. var de = function() {
  2. return (typeof(window.de) == 'object') ? window.de : {};
  3. }();

You can also highlight multiple lines:

 
 var de = function() {
 	return (typeof(window.de) == 'object') ? window.de : {};
 }();
 

This is the result:

  1. var de = function() {
  2. return (typeof(window.de) == 'object') ? window.de : {};
  3. }();

Line numbers can start at any given value:

 
 void main () {
     printf ("Hello World!");
     exit 0;
 }
 

This is the result:

  1. void main () {
  2. printf ("Hello World!");
  3. exit 0;
  4. }

Fair Use Source: https://www.dokuwiki.org/syntax_highlighting

syntax_highlighting.txt · Last modified: 2024/04/28 03:22 by 127.0.0.1