Inhaltsverzeichnis

Code

Syntax-Hervorhebung

DokuWiki kennt Syntax highlighting für Quellcode, um dessen Lesbarkeit zu erhöhen. Dafür wird GeSHi „Generic Syntax Highlighter“ benutzt. Somit wird jede Programmiersprache unterstützt, die GeSHi kennt. Es wird der Bezeichner code benutzt, und man muss nur den Namen der gewünschten Sprache angeben:

     <code vhdl> Quelltext </code>    

Herunterladbarer Quelltext

     <code vhdl name.vhd> Quelltext </code>

Es werden folgende Sprachen unterstützt: actionscript, actionscript-french, ada, apache, applescript, asm, asp, bash, caddcl, cadlisp, c, c_mac, cpp, csharp, css, delphi, diff, d, div, dos, eiffel, freebasic, gml, html4strict, ini, inno, java, javascript, lisp, lua, matlab, mpasm, nsis, objc, ocaml, ocaml-brief, oobas, oracle8, pascal, perl, php-brief, php, python, qbasic, scheme, sdlbasic, smarty, sql, ruby, vb, vbnet, vhdl, visualfoxpro, xml

Beispiele

vhdl

     <code vhdl> Quelltext </code>
process (clk, rst)
begin 
	if rst =1then 
		reg <=0;
	elsif clk =1and clk’rising then
		reg <= reg_in;
	end if;
end process;

vhdl zum herunterladen

     <code vhdl test.vhd> Quelltext </code>
test.vhd
process (clk, rst)
begin 
	if rst =1then 
		reg <=0;
	elsif clk =1and clk’rising then
		reg <= reg_in;
	end if;
end process;

java

     <code java> Quelltext </code>
/** 
 * 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.
    }
}

html

     <code html> Quelltext </code>
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
 <head>
  <title>
   Hello World Demonstration Document
  </title>
 </head>
 <body>
  <h1>
   Hello, World!
  </h1>
  <p>
 
   This is a minimal "hello world" HTML document. It demonstrates the
   basic structure of an HTML file and anchors.
  </p>
  <p>
   For more information, see the HTML Station at: <a href= 
   "http://www.december.com/html/">http://www.december.com/html/</a>
  </p>
  <hr>
  <address>
   &copy; <a href="http://www.december.com/john/">John December</a> (<a
   href="mailto:john@december.com">john@december.com</a>) / 2001-04-06
  </address>
 
 </body>
</html>

Another Sample

<sxh php; first-line: 70; highlight: [89,92]; title: New title attribute in action>

  public function render($mode, &$renderer, $data) {
  
      if($mode != 'xhtml') return false;
      if (count($data) == 3) {
          list($syntax, $attr, $content) = $data;
          if ($syntax == 'sxh') {
              // Check if there's a title in the attribute string. It can't be passed along as a normal parameter to SyntaxHighlighter.
              if (preg_match("/title:/i", $attr)) {
                  // Extract title(s) from attribute string.
                  $attr_array = explode(";",$attr);
                  $title_array = preg_grep("/title:/i", $attr_array);
                  // Extract everything BUT title(s) from attribute string.
                  $not_title_array =  preg_grep("/title:/i", $attr_array, PREG_GREP_INVERT);
                  $attr = implode(";",$not_title_array);
                  // If there are several titles, use the last one.
                  $title = array_pop($title_array);
                  $title = preg_replace("/.*title:\s{0,}(.*)/i","$1",$title);
                  // Add title as an attribute to the <pre /> tag.
                  $renderer->doc .= "<pre class=\"brush: ".$attr."\" title=\"".$title."\">".$renderer->_xmlEntities($content)."</pre>";
              } else {
                  // No title detected, pass all attributes as parameters to SyntaxHighlighter.
                  $renderer->doc .= "<pre class=\"brush: ".$attr."\">".$renderer->_xmlEntities($content)."</pre>";
              }
           } else {
              $renderer->file($content);
          }
      }
      return true;
  }

</sxh>