summaryrefslogtreecommitdiff
path: root/support/highlight/examples
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/highlight/examples
Initial commit
Diffstat (limited to 'support/highlight/examples')
-rw-r--r--support/highlight/examples/highlight_pipe.php170
-rw-r--r--support/highlight/examples/highlight_pipe.pm65
-rw-r--r--support/highlight/examples/highlight_pipe.py46
-rw-r--r--support/highlight/examples/plugins/dokuwiki/syntax.php242
-rw-r--r--support/highlight/examples/plugins/movabletype/README35
-rw-r--r--support/highlight/examples/plugins/movabletype/highlight.pl88
-rw-r--r--support/highlight/examples/plugins/serendipity_event_highlight/lang_de.inc.php32
-rw-r--r--support/highlight/examples/plugins/serendipity_event_highlight/lang_en.inc.php32
-rw-r--r--support/highlight/examples/plugins/serendipity_event_highlight/serendipity_event_highlight.php329
-rw-r--r--support/highlight/examples/plugins/wordpress/README33
-rw-r--r--support/highlight/examples/plugins/wordpress/highlight.php140
-rw-r--r--support/highlight/examples/swig/README_SWIG21
-rw-r--r--support/highlight/examples/swig/highlight.i13
-rw-r--r--support/highlight/examples/swig/makefile34
-rw-r--r--support/highlight/examples/swig/testmod.pl28
-rw-r--r--support/highlight/examples/swig/testmod.py88
16 files changed, 1396 insertions, 0 deletions
diff --git a/support/highlight/examples/highlight_pipe.php b/support/highlight/examples/highlight_pipe.php
new file mode 100644
index 0000000000..0e0f690bf5
--- /dev/null
+++ b/support/highlight/examples/highlight_pipe.php
@@ -0,0 +1,170 @@
+<?php
+
+/**This PHP class serves as interface to the highlight utility.
+Input and output streams are handled with pipes.
+Command line parameters are validated before use.
+*/
+
+class HighlightPipe {
+
+ // alter these members to control highlight output
+ // see manpage for the options
+
+ var $hl_option = array(
+ 'hl_bin' => 'highlight', // configure path of highlight binary
+ 'syntax' => 'txt',
+ 'theme' => 'kwrite',
+ 'force' => 1,
+ 'linenumbers' => 0,
+ 'line-number-length' => 4,
+ 'line-number-start' => 0,
+ 'zeroes' => 0,
+ 'wraptype' => 0,
+ 'line-length' => 0,
+ 'reformat' => '',
+ 'kw-case' => '',
+ 'replace-tabs' => 0,
+ 'encoding' => '',
+ 'enclose-pre' => 1,
+ 'inline-css' => 1,
+ 'fragment' => 1,
+ );
+
+ // this member contains the input source code
+ var $input='';
+
+ // this member will contain the command string after getResult() was called
+ var $hl_cmd_str='';
+
+ function getInfo(){
+ return array(
+ 'author' => 'Andre Simon',
+ 'email' => 'andre.simon1@gmx.de',
+ 'date' => '2008-02-20',
+ 'url' => 'http://www.andre-simon.de/',
+ 'version' => '1.1',
+ );
+ }
+
+ // call this method to generate highlighted HTML code
+ function getResult() {
+
+ foreach ($this->hl_option as $key => $value) {
+ $this->hl_option[$key] = $this->validate( $value );
+ }
+
+ $descriptorspec = array(
+ 0 => array("pipe", "r"),
+ 1 => array("pipe", "w")
+ );
+
+ $this->hl_cmd_str = $this->hl_option['hl_bin'];
+
+ if ($this->hl_option['linenumbers']){
+ $this->hl_cmd_str .= " -l -m 1";
+ /*$this->hl_cmd_str .= $this->get_config('hl_linenumbersberstart');*/
+ if ($this->hl_option['zeroes']){
+ $this->hl_cmd_str .= " -z ";
+ }
+ if ($this->hl_option['line-number-length']!='0' && is_numeric($this->hl_option['line-number-length'])) {
+ $this->hl_cmd_str .= ' -j ';
+ $this->hl_cmd_str .=$this->hl_option['line-number-length'];
+ }
+ }
+
+ if (is_numeric($this->hl_option['replace-tabs']) and $this->hl_option['replace-tabs']>0) {
+ $this->hl_cmd_str .= " -t ";
+ $this->hl_cmd_str .= $this->hl_option['replace-tabs'];
+ }
+
+ if ($this->hl_option['wraptype']>0){
+ $this->hl_cmd_str .= ($this->hl_option['wraptype'] == 1)? ' -V ':' -W ';
+ if ($this->hl_option['line-length']>0 && is_numeric($this->hl_option['line-length'])) {
+ $this->hl_cmd_str .= " -J ";
+ $this->hl_cmd_str .= $this->hl_option['line-length'];
+ }
+ }
+
+ if (strlen($this->hl_option['reformat'])>1){
+ $this->hl_cmd_str .= " -F ";
+ $this->hl_cmd_str .= $this->hl_option['reformat'];
+ }
+
+ if (strlen($this->hl_option['kw-case'])>1){
+ $this->hl_cmd_str .= " --kw-case ";
+ $this->hl_cmd_str .= $this->hl_option['kw-case'];
+ }
+
+ if ($this->hl_option['force']){
+ $this->hl_cmd_str .= " --force ";
+ }
+
+ if ($this->hl_option['inline-css']){
+ $this->hl_cmd_str .= " --inline-css ";
+ }
+
+ if ($this->hl_option['fragment']){
+ $this->hl_cmd_str .= " -f ";
+ }
+
+ if ($this->hl_option['theme']){
+ $this->hl_cmd_str .= " -s ";
+ $this->hl_cmd_str .= $this->hl_option['theme'];
+ }
+
+ if ($this->hl_option['encoding']){
+ $this->hl_cmd_str .= " -u ";
+ $this->hl_cmd_str .= $this->hl_option['encoding'];
+ }
+
+ if ($this->hl_option['enclose-pre']){
+ $this->hl_cmd_str .= " --enclose-pre ";
+ }
+
+ $this->hl_cmd_str .= " -S ";
+ $this->hl_cmd_str .= $this->hl_option['syntax'];
+
+ $process = proc_open($this->hl_cmd_str, $descriptorspec, $pipes);
+ if (is_resource($process)) {
+
+ fwrite($pipes[0], $this->input);
+ fclose($pipes[0]);
+
+ $output = stream_get_contents($pipes[1]);
+ fclose($pipes[1]);
+
+ // It is important that you close any pipes before calling
+ // proc_close in order to avoid a deadlock
+ proc_close($process);
+ }
+ return $output;
+ }
+
+
+ // PRIVATE STUFF
+ var $special = array(' ', '/','!','&','*','\\', '.', '|', '´','\'', '<', '>');
+
+ function validate($string) {
+ return (strlen($string)>50)? "" : str_replace($this->special,"",$string);
+ }
+
+ }
+
+/*****************************************************************************/
+
+/*
+
+// Sample code:
+
+ $generator = new HighlightPipe;
+ $generator->input='int main () { return 0; }';
+
+ $generator->hl_option['theme']='neon';
+ $generator->hl_option['syntax']='c';
+
+ $result= $generator->getResult();
+
+ print $result;
+*/
+
+?> \ No newline at end of file
diff --git a/support/highlight/examples/highlight_pipe.pm b/support/highlight/examples/highlight_pipe.pm
new file mode 100644
index 0000000000..6435501b5b
--- /dev/null
+++ b/support/highlight/examples/highlight_pipe.pm
@@ -0,0 +1,65 @@
+package highlight_pipe;
+
+# This Perl package serves as interface to the highlight utility.
+# Input and output streams are handled with pipes.
+# Command line parameter length is validated before use.
+
+use IPC::Open3;
+
+my $hl_bin='highlight';
+
+sub new {
+ my $object = shift;
+ my $ref = {};
+ bless($ref,$object);
+ return($ref);
+}
+
+sub getResult {
+ my $object = shift;
+ my $src = shift;
+
+ my @hl_args = ();
+ my $option;
+ while ( my ($key, $value) = each(%$object) ) {
+ $option =" --$key";
+ if ($value ne "1") {$option .= "=$value"};
+ if (length($option)<50) { push (@hl_args, $option); }
+ }
+ local(*HIS_IN, *HIS_OUT, *HIS_ERR);
+
+ my $childpid = IPC::Open3::open3(\*HIS_IN, \*HIS_OUT, \*HIS_ERR, $hl_bin. join ' ', @hl_args)
+ or die ("error invoking highlight");
+
+ print HIS_IN $src;
+ close(HIS_IN); # Give end of file to kid.
+
+ my @outlines = <HIS_OUT>; # Read till EOF.
+ my @errlines = <HIS_ERR>; # Read till EOF.
+ close HIS_OUT;
+ close HIS_ERR;
+ waitpid($childpid, 0);
+
+ if (@errlines) { die (join '\n', @errlines); }
+
+ return join '', @outlines;
+}
+
+###############################################################################
+# Sample code:
+
+# insert use statement in other perl scripts:
+#use highlight_pipe;
+
+my $html = highlight_pipe -> new();
+
+$html->{'syntax'} ='c';
+$html->{'fragment'} = 1;
+$html->{'inline-css'} = 1;
+$html->{'enclose-pre'} = 1;
+$html->{'style'} = 'vim';
+
+my $input='int main () { return 0; }';
+my $output=$html->getResult($input);
+
+print "Result:\n$output\n";
diff --git a/support/highlight/examples/highlight_pipe.py b/support/highlight/examples/highlight_pipe.py
new file mode 100644
index 0000000000..b9132a91bc
--- /dev/null
+++ b/support/highlight/examples/highlight_pipe.py
@@ -0,0 +1,46 @@
+from subprocess import *
+
+class HighlightPipe:
+ """ This Python package serves as interface to the highlight utility.
+ Input and output streams are handled with pipes.
+ Command line parameter length is validated before use."""
+
+ def __init__(self):
+ self.cmd = 'highlight'
+ self.src=''
+ self.options=dict()
+ self.success=False
+
+ def getResult(self):
+ cmd = self.cmd
+ for k, v in self.options.iteritems():
+ option=" --%s" % k
+ if ( v != '1'): option += "=%s" % v
+ if (len(option)<50): cmd += option
+ p = Popen(cmd, shell=True, bufsize=512, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
+ (child_stdin, child_stdout, child_stderr) = (p.stdin, p.stdout, p.stderr)
+
+ child_stdin.write(self.src)
+ child_stdin.close()
+ err_msg = child_stderr.readlines()
+ if (len(err_msg)>0): return err_msg
+ self.success=True
+ return child_stdout.readlines()
+
+
+###############################################################################
+
+def main():
+ gen = HighlightPipe();
+ gen.options['syntax'] = 'c'
+ gen.options['style'] = 'vim'
+ gen.options['enclose-pre'] = '1'
+ gen.options['fragment'] = '1'
+ gen.options['inline-css'] = '1'
+ gen.src = 'int main ()\n{ return 0; }'
+
+ print gen.getResult()
+ if not gen.success: print "Execution failed."
+
+if __name__=="__main__":
+ main()
diff --git a/support/highlight/examples/plugins/dokuwiki/syntax.php b/support/highlight/examples/plugins/dokuwiki/syntax.php
new file mode 100644
index 0000000000..b47e8fabde
--- /dev/null
+++ b/support/highlight/examples/plugins/dokuwiki/syntax.php
@@ -0,0 +1,242 @@
+<?php
+/*
+Plugin Name: Highlight
+Plugin URI: http://www.andre-simon.de
+Description: Plugin which uses the highlight utility to generate coloured source code
+Author: André Simon
+Version: 1.2
+Author URI: http://www.andre-simon.de
+
+
+This file is part of Highlight.
+
+Highlight is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Highlight is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Highlight. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/*
+== Description ==
+
+The highlight utility converts source code of 120 programming languages to HTML
+with syntax highlighting. This plugin pipes the content of <highlight>-Tags associated
+with a lang parameter to highlight, and returns the output code which is included
+in the Wiki page.
+
+Usage:
+
+Paste the following in the edit section of the wiki editing form:
+
+<highlight cpp>#include <stdio.h>
+
+int main (void){
+ printf("This is some random code");
+ return 0;
+}</highlight>
+
+Use the lang parameter to define the programming language (c, php, py, xml, etc).
+See the highlight documentation to learn all possible languages.
+See the syntax.php file for some formatting options (line numbering, code
+indentation, line wrapping etc).
+
+== Installation ==
+
+1. Install highlight (www.andre-simon.de) on your host
+2. Unzip the dokuwiki_highlight.zip file and upload the content to the
+ `lib/plugins/` directory
+ */
+
+if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
+if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
+require_once(DOKU_PLUGIN.'syntax.php');
+
+class syntax_plugin_highlight extends DokuWiki_Syntax_Plugin {
+
+ function getInfo(){
+ return array(
+ 'author' => 'Andre Simon',
+ 'email' => 'andre.simon1@gmx.de',
+ 'date' => '2007-05-29',
+ 'name' => 'Highlight Plugin',
+ 'desc' => 'Plugin which uses the highlight utility (http://www.andre-simon.de) instead of Geshi for source code highlighting',
+ 'url' => 'http://wiki.splitbrain.org/wiki:plugins',
+ );
+ }
+
+ /**
+ * What kind of syntax are we?
+ */
+ function getType(){
+ return 'formatting';
+ }
+
+ /**
+ * What kind of syntax do we allow (optional)
+ */
+// function getAllowedTypes() {
+// return array();
+// }
+
+ /**
+ * What about paragraphs? (optional)
+ */
+ function getPType(){
+ return 'block';
+ }
+
+ /**
+ * Where to sort in?
+ */
+ function getSort(){
+ return 199;
+ }
+
+
+ /**
+ * Connect pattern to lexer
+ */
+ function connectTo($mode) {
+ $this->Lexer->addEntryPattern('<highlight(?=[^\r\n]*?>.*?</highlight>)',$mode,'plugin_highlight');
+ }
+
+ function postConnect() {
+ $this->Lexer->addExitPattern('</highlight>','plugin_highlight');
+ }
+
+ /**
+ * Handle the match
+ */
+ function handle($match, $state, $pos, &$handler){
+
+ switch ($state) {
+ case DOKU_LEXER_ENTER :
+ break;
+ case DOKU_LEXER_UNMATCHED :
+ list($lang, $content) = preg_split('/>/u',$match,2);
+ $lang = trim($lang);
+ return array($state, $lang, $content);
+
+ case DOKU_LEXER_EXIT :
+ break;
+ }
+ return array();
+ }
+
+ /**
+ * Create output
+ */
+ function render($mode, &$renderer, $data) {
+ // Highlight options:
+ $hl_options=array();
+ $hl_options['hl_binary']='/highlight'; // path to the highlight binary
+ $hl_options['linenumbers']=false;
+ $hl_options['theme']='kwrite'; // set color theme
+ $hl_options['linenumber-start']=1;
+ $hl_options['linenumber-zeroes']=1; // set to 1 if line numbers should be padded with zeros
+ $hl_options['linenumber-length']=2;
+ $hl_options['reformat-style']="gnu"; // possible values for C, C++ and Java Code: ansi, gnu, java, kr, linux
+ $hl_options['replace-tabs']=4; //number of spaces which replace a tab
+ $hl_options['wrap-style']=2; //0 -> disable, 1-> wrap, 2-> wrap and indent function names
+ $hl_options['wrap-line-length']=80; // if wrap-style <>0, this defines the line length before wrapping takes place
+
+
+ if($mode == 'xhtml'){
+ list($state, $lang, $input_code) = $data;
+ $lang = preg_replace("'[^a-zA-Z]'","",$lang);
+ switch ($state) {
+ case DOKU_LEXER_ENTER :
+ break;
+
+ case DOKU_LEXER_UNMATCHED : // $renderer->doc .= $renderer->_xmlEntities($match); break;
+
+ $search = array("&amp;","&quot;", "&lt;", "&gt;","&#92;","&#39;","&nbsp;");
+ $replace = array("&","\"", "<", ">","\\","\'", " ");
+ $input_code = str_replace($search, $replace, $input_code);
+
+ $descriptorspec = array(
+ 0 => array("pipe", "r"), // stdin is a pipe that the child will read from
+ 1 => array("pipe", "w") // stdout is a pipe that the child will write to
+ );
+
+ $hl_cmd_str = $hl_options['hl_binary'];
+ $hl_cmd_str .= ' --inline-css -f ';
+
+ if ($hl_options['linenumbers']){
+ $hl_cmd_str .= " -l -m ";
+ $hl_cmd_str .= $hl_options['linenumber-start'];
+ if ($hl_options['linenumber-zeroes']){
+ $hl_cmd_str .= " -z -j ";
+ $hl_cmd_str .= $hl_options['linenumber-length'];
+ }
+ }
+
+ if ($hl_options['replace-tabs']) {
+ $hl_cmd_str .= " -t ";
+ $hl_cmd_str .= $hl_options['replace-tabs'];
+ }
+
+ if ($hl_options['wrap-style']){
+ $hl_cmd_str .= ($hl_options['wrap-style'] == 1)? ' -V ':' -W ';
+ $hl_cmd_str .= " -J ";
+ $hl_cmd_str .= $hl_options['wrap-line-length'];
+ }
+
+ if ($hl_options['reformat-style']){
+ $hl_cmd_str .= " -F ";
+ $hl_cmd_str .= $hl_options['reformat-style'];
+ }
+
+ if ($hl_options['theme']){
+ $hl_cmd_str .= " -s ";
+ $hl_cmd_str .= $hl_options['theme'];
+ }
+
+ $hl_cmd_str .= " -S $lang ";
+
+ $process = proc_open($hl_cmd_str, $descriptorspec, $pipes);
+
+ if (is_resource($process)) {
+
+ fwrite($pipes[0], $input_code);
+ fclose($pipes[0]);
+
+ $output = stream_get_contents($pipes[1]);
+ fclose($pipes[1]);
+
+ // It is important that you close any pipes before calling
+ // proc_close in order to avoid a deadlock
+ proc_close($process);
+ }
+ if (!strlen($output)) {
+ $renderer->doc .= "<small>ERROR: Execution of highlight ($hl_cmd_str) failed or missing input. Check binary path.</small>";
+ $renderer->doc .= "<pre style=\"font-size:9pt;\">";
+ $renderer->doc .= $renderer->_xmlEntities($input_code);
+ $renderer->doc .= "</pre>";
+
+ } else {
+ $renderer->doc .= "<pre style=\"font-size:9pt;\">";
+ $renderer->doc .= $output;
+ $renderer->doc .= "</pre>";
+ }
+
+ //$renderer->doc .= "<br>cmd=".$hl_cmd_str;
+
+ break;
+ case DOKU_LEXER_EXIT :
+ break;
+ }
+ return true;
+ }
+ return false;
+ }
+}
+
diff --git a/support/highlight/examples/plugins/movabletype/README b/support/highlight/examples/plugins/movabletype/README
new file mode 100644
index 0000000000..0988649366
--- /dev/null
+++ b/support/highlight/examples/plugins/movabletype/README
@@ -0,0 +1,35 @@
+Plugin Name: Highlight
+Plugin URI: http://www.andre-simon.de
+Description: Plugin which uses the highlight utility to generate coloured source code
+Author: André Simon
+Version: 1.2
+Author URI: http://www.andre-simon.de/
+
+== Description ==
+
+The highlight utility converts source code of 120 programming languages to HTML
+with syntax highlighting. This plugin pipes the content of <highlight>-Tags associated
+with a lang parameter to highlight, and returns the output code which is finally included
+in the MT page.
+
+Usage:
+
+Paste the following in the edit section of the MT blog editing form:
+
+<highlight lang="cpp">#include <stdio.h>
+
+int main (void){
+ printf("This is some random code");
+ return 0;
+}</highlight>
+
+Use the lang parameter to define the programming language (c, php, py, xml, etc).
+See the highlight documentation to learn all possible languages.
+See the syntax.php file for some formatting options (line numbering, code
+indentation, line wrapping etc).
+
+== Installation ==
+
+1. Install highlight (www.andre-simon.de) on your host
+2. Unzip the mt_highlight.zip file and upload the content to the
+ `plugins/` directory \ No newline at end of file
diff --git a/support/highlight/examples/plugins/movabletype/highlight.pl b/support/highlight/examples/plugins/movabletype/highlight.pl
new file mode 100644
index 0000000000..57d107633f
--- /dev/null
+++ b/support/highlight/examples/plugins/movabletype/highlight.pl
@@ -0,0 +1,88 @@
+#Plugin Name: Highlight
+#Plugin URI: http://www.andre-simon.de
+#Description: Plugin which uses the highlight utility to generate coloured source code
+#Author: André Simon
+#Version: 1.2
+#Author URI: http://www.andre-simon.de/
+
+#This file is part of Highlight.
+#
+#Highlight is free software: you can redistribute it and/or modify
+#it under the terms of the GNU General Public License as published by
+#the Free Software Foundation, either version 3 of the License, or
+#(at your option) any later version.
+#
+#Highlight is distributed in the hope that it will be useful,
+#but WITHOUT ANY WARRANTY; without even the implied warranty of
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+#GNU General Public License for more details.
+#
+#You should have received a copy of the GNU General Public License
+#along with Highlight. If not, see <http://www.gnu.org/licenses/>.
+
+package MT::Plugin::Highlight;
+
+use strict;
+use IPC::Open3;
+use MT;
+use MT::Entry;
+use MT::Plugin;
+use MT::Template::Context;
+use MT::WeblogPublisher;
+
+my $plugin = new MT::Plugin();
+$plugin->name("MT Highlight");
+$plugin->description('Source code highlighter using highlight (http://www.andre-simon.de)');
+$plugin->doc_link('http://wiki.andre-simon.de/');
+$plugin->author_name('Andre Simon');
+$plugin->author_link('http://www.andre-simon.de/');
+$plugin->plugin_link('http://wiki.andre-simon.de/');
+$plugin->version('1.2');
+
+MT->add_callback("BuildPage", 1, $plugin, \&highlight_callback);
+MT->add_plugin($plugin);
+
+sub highlight_callback
+{
+ my ($cb, %args) = @_;
+ use Data::Dumper;
+ my $html = ${$args{'Content'}};
+ $html =~ s/<highlight([^>]*?)lang="([^"]+?)"([^>]*?)>(.*?)<\/highlight>/highlight_code($2,$4)/ges;
+ ${$args{'Content'}} = $html;
+ return 1;
+}
+
+sub highlight_code
+{
+ my ($lang, $source) = @_;
+
+ $lang =~ s/[^a-zA-Z]//g; # delete special chars in user input
+ $source =~ s/\<br \/\>//g; # get rid of <br> Tags inserted by MT
+ $source =~ s/\<\/?p\>//g; # MT inserts <p> Tags if <, > are present in input code
+
+ local(*HIS_IN, *HIS_OUT, *HIS_ERR);
+
+ my @hl_args = ('-f', "-S$lang");
+ push (@hl_args, '--inline-css'); # use inline css definitions
+ push (@hl_args, '-skwrite'); # coloring theme
+ push (@hl_args, '-l'); # linenumbers
+ push (@hl_args, '-j2'); # linenumber length
+ push (@hl_args, '-z'); # linenumber zeroes
+ push (@hl_args, '-Fgnu'); # reformat
+ push (@hl_args, '-t4'); # replace tabs
+ my $childpid = IPC::Open3::open3(*HIS_IN, *HIS_OUT, *HIS_ERR, 'highlight', @hl_args);
+ print HIS_IN $source;
+ close(HIS_IN); # Give end of file to kid.
+ my @outlines = <HIS_OUT>; # Read till EOF.
+
+ close HIS_OUT;
+ close HIS_ERR;
+ waitpid($childpid, 0);
+
+ my $htext = join "", @outlines;
+
+ return "<pre>".$htext."</pre>";
+}
+
+
+
diff --git a/support/highlight/examples/plugins/serendipity_event_highlight/lang_de.inc.php b/support/highlight/examples/plugins/serendipity_event_highlight/lang_de.inc.php
new file mode 100644
index 0000000000..508858ca3f
--- /dev/null
+++ b/support/highlight/examples/plugins/serendipity_event_highlight/lang_de.inc.php
@@ -0,0 +1,32 @@
+<?php
+
+@define('PLUGIN_EVENT_HIGHLIGHT_NAME', 'Markup: Highlight');
+@define('PLUGIN_EVENT_HIGHLIGHT_DESC', 'Farbige Syntax-Hervorhebung mit dem highlight tool. Einbindung mit dem Tag: [highlight lang=langName ] code [/highlight]');
+@define('PLUGIN_EVENT_HIGHLIGHT_TRANSFORM', 'Benutzen Sie <b>[highlight lang=langName][/highlight]</b> Tags, um Sourcecode farbig hervorzuheben.');
+@define('PLUGIN_EVENT_HIGHLIGHT_VERSION','01');
+
+@define('PLUGIN_EVENT_HIGHLIGHT_HLBINDIR','Highlight Pfad');
+@define('PLUGIN_EVENT_HIGHLIGHT_HLBINDIR_DESC','Pfad der highlight Programdatei');
+@define('PLUGIN_EVENT_HIGHLIGHT_HLDATADIR','Highlight Datenverzeichnis');
+@define('PLUGIN_EVENT_HIGHLIGHT_HLDATADIR_DESC','Dieses Verzeichnis enthält die Programmdaten, z.B. die Unterverzeichnisse langDefs, themes etc');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERS', 'Ausgabe Zeilennummern');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERS_DESC','Sollen Zeilennummern ausgegeben werden?');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERZEROES', 'Zeilennummern füllen');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERZEROES_DESC','Sollen Zeilennummern mit Nullen aufgefüllt werden?');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERSTART', 'Beginn der Nummerierung');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERSTART_DESC','Wo soll die Nummerierung beginnen?');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERLEN', 'Zeilennnummernbreite');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERLEN_DESC','Mit wievielen Stellen soll die Nummerierung ausgegeben werden?');
+@define('PLUGIN_EVENT_HIGHLIGHT_THEMES', 'Farbschema');
+@define('PLUGIN_EVENT_HIGHLIGHT_THEMES_DESC','Wähle ein Farbschema aus, das zu deinem Blog-Style passt.');
+@define('PLUGIN_EVENT_HIGHLIGHT_FORMAT', 'Neuformatierung und Einrückung');
+@define('PLUGIN_EVENT_HIGHLIGHT_FORMAT_DESC','Wähle ein Schema aus, um C, C++, C# und Java Code einheitlich zu formatieren.');
+
+@define('PLUGIN_EVENT_HIGHLIGHT_WRAP', 'Zeilenumbruch');
+@define('PLUGIN_EVENT_HIGHLIGHT_WRAP_DESC','Bestimme, ob Zeilen umgebrochen werden sollen. WRAP INTELLIGENT bedeutet, dass Funktionsparameter und Zuweisungen nach dem Umbruch korrekt eingerückt werden.');
+@define('PLUGIN_EVENT_HIGHLIGHT_WRAPLEN', 'Zeilenlänge vor Umbruch');
+@define('PLUGIN_EVENT_HIGHLIGHT_WRAPLEN_DESC','Gib die maximale Zeilenlänge an (nur wirksam wenn obige Option Zeilenumbruch nicht deaktiviert ist).');
+@define('PLUGIN_EVENT_HIGHLIGHT_TABLEN', 'Tabulatorbreite');
+@define('PLUGIN_EVENT_HIGHLIGHT_TABLEN_DESC','Bestimme die Anzahl von Leerzeichen, die ein Tab ersetzen.');
+
+?>
diff --git a/support/highlight/examples/plugins/serendipity_event_highlight/lang_en.inc.php b/support/highlight/examples/plugins/serendipity_event_highlight/lang_en.inc.php
new file mode 100644
index 0000000000..cf8a6e24d1
--- /dev/null
+++ b/support/highlight/examples/plugins/serendipity_event_highlight/lang_en.inc.php
@@ -0,0 +1,32 @@
+<?php
+
+@define('PLUGIN_EVENT_HIGHLIGHT_NAME', 'Markup: Highlight');
+@define('PLUGIN_EVENT_HIGHLIGHT_DESC', 'Coloured Syntax Highlighting using the highlight utility. Tag usage: [highlight lang=langName ] code [/highlight]');
+@define('PLUGIN_EVENT_HIGHLIGHT_TRANSFORM', 'You can use <b>[highlight lang=langName][/highlight]</b> tags to embed source code snippets');
+@define('PLUGIN_EVENT_HIGHLIGHT_VERSION','01');
+
+@define('PLUGIN_EVENT_HIGHLIGHT_HLBINDIR','Path of highlight binary');
+@define('PLUGIN_EVENT_HIGHLIGHT_HLBINDIR_DESC','Path of the highlight binary');
+@define('PLUGIN_EVENT_HIGHLIGHT_HLDATADIR','Path of highlight data directory');
+@define('PLUGIN_EVENT_HIGHLIGHT_HLDATADIR_DESC','This directory contains the data files located in the subdirectories langDefs, themes etc');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERS', 'Line number printout');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERS_DESC','Define if the line numbers should be shown.');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERZEROES', 'Line number padding');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERZEROES_DESC','Define if the line numbers should be padded with zeroes.');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERSTART', 'Line number start');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERSTART_DESC','Define where the line numbering should start.');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERLEN', 'Line number width');
+@define('PLUGIN_EVENT_HIGHLIGHT_LINENUMBERLEN_DESC','Define the line number width.');
+@define('PLUGIN_EVENT_HIGHLIGHT_THEMES', 'Color theme');
+@define('PLUGIN_EVENT_HIGHLIGHT_THEMES_DESC','Choose a color theme which matches your blog.');
+@define('PLUGIN_EVENT_HIGHLIGHT_FORMAT', 'Code reformatting');
+@define('PLUGIN_EVENT_HIGHLIGHT_FORMAT_DESC','Choose a indentation and reformatting scheme to reformat C, C++, C# and Java code.');
+
+@define('PLUGIN_EVENT_HIGHLIGHT_WRAP', 'Line wrapping');
+@define('PLUGIN_EVENT_HIGHLIGHT_WRAP_DESC','Define if long lines should be wrapped. WRAP INTELLIGENT means that function parameters and assignments are intended after wrapping.');
+@define('PLUGIN_EVENT_HIGHLIGHT_WRAPLEN', 'Line length before wrapping');
+@define('PLUGIN_EVENT_HIGHLIGHT_WRAPLEN_DESC','Set the maximum line length (only available if line wrapping is not disabled above).');
+@define('PLUGIN_EVENT_HIGHLIGHT_TABLEN', 'Tab width');
+@define('PLUGIN_EVENT_HIGHLIGHT_TABLEN_DESC','Define how many spaces should replace a tab.');
+
+?>
diff --git a/support/highlight/examples/plugins/serendipity_event_highlight/serendipity_event_highlight.php b/support/highlight/examples/plugins/serendipity_event_highlight/serendipity_event_highlight.php
new file mode 100644
index 0000000000..7c30a84e73
--- /dev/null
+++ b/support/highlight/examples/plugins/serendipity_event_highlight/serendipity_event_highlight.php
@@ -0,0 +1,329 @@
+<?php
+/**
+
+serendipity_event_highlight.php
+
+=== Highlight plugin ===
+
+This plugin uses highlight (http://www.andre-simon.de/) to add syntax highlighting to serendipity.
+
+== Description ==
+
+The highlight utility converts source code of 120 programming languages to HTML
+with syntax highlighting. This plugin pipes the content of [highlight] tags associated
+with a lang parameter to highlight, and returns the output code which is included
+in the Serendipity blog entry.
+The plugin configuration menu offers the most important options of the highlight utility.
+The highlighted code is formatted with inline CSS to avoid complicated plugin setup.
+
+Usage:
+
+Paste the following in the code section of the blog editing form:
+
+[highlight lang=c]#include <stdio.h>
+
+int main (void){
+ printf("This is some random code");
+ return 0;
+} [/highlight]
+
+Normally the file extension can be used for the lang parameter (like pl, py, java, pas etc).
+Execute 'highlight --list-langs' to get a list of all supported programming langauges.
+
+== Installation ==
+
+1. Install the highlight utility on your host (www.andre-simon.de)
+2. Copy the serendipity_event_highlight dir into the serendipity plugin dir
+3. Activate and configure the plugin in the serendipity administration menu
+
+ IMPORTANT:
+ To avoid insertion of superfluous <br> Tags by the nl2br plugin, add the
+ string "highlight" to the "list of HTML-tags where no breaks shall be
+ converted" in the nl2br configuration menu.
+
+ */
+
+
+if (IN_serendipity !== true) {
+ die ("Don't hack!");
+}
+
+// Probe for a language include with constants. Still include defines later on, if some constants were missing
+$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
+if (file_exists($probelang)) {
+ include $probelang;
+}
+
+include dirname(__FILE__) . '/lang_en.inc.php';
+
+class serendipity_event_highlight extends serendipity_event
+{
+ var $title = PLUGIN_EVENT_HIGHLIGHT_NAME;
+ // Top Level Configuration, requires name of the Plugin, description text, and configuration information in an array..
+ function introspect(&$propbag)
+ {
+ global $serendipity;
+
+ $propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_NAME);
+ $propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_DESC);
+ $propbag->add('stackable', false);
+ $propbag->add('author', 'Andre Simon');
+ $propbag->add('requirements', array(
+ 'serendipity' => '0.9',
+ 'highlight' => '2.6.4'
+ ));
+ $propbag->add('version', '0.1');
+ $propbag->add('event_hooks', array('frontend_display' => true, 'frontend_comment' => true));
+ $propbag->add('groups', array('MARKUP'));
+
+ $this->markup_elements = array(
+ array(
+ 'name' => 'ENTRY_BODY',
+ 'element' => 'body',
+ ),
+ array(
+ 'name' => 'EXTENDED_BODY',
+ 'element' => 'extended',
+ ),
+ array(
+ 'name' => 'COMMENT',
+ 'element' => 'comment',
+ ),
+ array(
+ 'name' => 'HTML_NUGGET',
+ 'element' => 'html_nugget',
+ )
+ );
+
+ #Colour themes of a highlight default installation
+ $this->themes = array(
+ "acid", "bipolar", "blacknblue", "bright", "contrast", "darkblue", "darkness", "desert", "dull", "easter", "emacs", "golden", "greenlcd",
+ "ide-anjuta", "ide-codewarrior", "ide-devcpp", "ide-eclipse", "ide-kdev", "ide-msvcpp", "ide-xcode", "kwrite", "lucretia", "matlab", "navy",
+ "nedit", "neon", "night", "orion", "pablo", "peachpuff", "print", "rand01", "seashell", "the", "typical", "vampire", "vim-dark", "vim",
+ "whitengrey", "zellner"
+ );
+
+ #Reformatting schemes of a highlight default installation
+ $this->reformatschemes = array ("disabled","ansi", "gnu", "java", "kr", "linux");
+
+ #highlight output options
+ $conf_array = array('hl_bin_dir','hl_data_dir','hl_linenumbers','hl_linenumberstart','hl_linenumberzeroes','hl_linenumberlen',
+ 'hl_wrap','hl_wrap_len','hl_tab_len', 'hl_theme','hl_format');
+
+ foreach($this->markup_elements as $element) {
+ $conf_array[] = $element['name'];
+ }
+ $propbag->add('configuration', $conf_array);
+ }
+
+ function generate_content(&$title) {
+ $title = $this->title;
+ }
+
+
+ function introspect_config_item($name, &$propbag) {
+ switch ($name) {
+ case 'hl_bin_dir' :
+ $propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_HLBINDIR);
+ $propbag->add('type', 'string');
+ $propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_HLBINDIR_DESC);
+ $propbag->add('default', 'highlight');
+ break;
+ case 'hl_data_dir' :
+ $propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_HLDATADIR);
+ $propbag->add('type', 'string');
+ $propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_HLDATADIR_DESC);
+ $propbag->add('default', '/usr/share/highlight/');
+ break;
+ case 'hl_linenumbers' :
+ $propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERS);
+ $propbag->add('type', 'boolean');
+ $propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERS_DESC);
+ $propbag->add('default', 'false');
+ break;
+ case 'hl_linenumberzeroes' :
+ $propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERZEROES);
+ $propbag->add('type', 'boolean');
+ $propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERZEROES_DESC);
+ $propbag->add('default', 'false');
+ break;
+ case 'hl_linenumberstart' :
+ $propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERSTART);
+ $propbag->add('type', 'string');
+ $propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERSTART_DESC);
+ $propbag->add('default', '1');
+ $propbag->add('validate', 'number');
+ break;
+
+ case 'hl_linenumberlen' :
+ $propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERLEN);
+ $propbag->add('type', 'string');
+ $propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_LINENUMBERLEN_DESC);
+ $propbag->add('default', '2');
+ $propbag->add('validate', 'number');
+ break;
+
+ case 'hl_theme' :
+ $propbag->add('type', 'select');
+ $propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_THEMES);
+ $propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_THEMES_DESC);
+ $propbag->add('select_values', $this->themes);
+ $propbag->add('default', '1');
+ break;
+
+ case 'hl_format' :
+ $propbag->add('type', 'select');
+ $propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_FORMAT);
+ $propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_FORMAT_DESC);
+ $propbag->add('select_values', $this->reformatschemes);
+ $propbag->add('default', '0');
+ break;
+
+ case 'hl_wrap' :
+ $wrapstyles=array ('No wrap', 'Simple wrap','Intelligent wrap');
+ $propbag->add('type', 'select');
+ $propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_WRAP);
+ $propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_WRAP_DESC);
+ $propbag->add('select_values', $wrapstyles);
+ $propbag->add('default', '0');
+ break;
+ case 'hl_wrap_len' :
+ $propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_WRAPLEN);
+ $propbag->add('type', 'string');
+ $propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_WRAPLEN_DESC);
+ $propbag->add('default', '60');
+ $propbag->add('validate', 'number');
+ break;
+ case 'hl_tab_len' :
+ $propbag->add('name', PLUGIN_EVENT_HIGHLIGHT_TABLEN);
+ $propbag->add('type', 'string');
+ $propbag->add('description', PLUGIN_EVENT_HIGHLIGHT_TABLEN_DESC);
+ $propbag->add('default', '4');
+ $propbag->add('validate', 'number');
+ break;
+ default :
+ $propbag->add('name', constant($name));
+ $propbag->add('type', 'boolean');
+ $propbag->add('default', 'true');
+ $propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
+ }
+ return true;
+ }
+
+ function geshi($input) {
+ $input = preg_replace_callback('/\[highlight(?:\s)*lang=([A-Za-z0-9_\-]+)(?:\s)*()?\](.*?)\[\/highlight\]/si', array(&$this, 'highlightcallback'), $input);
+ return $input;
+ }
+
+ function event_hook($event, &$bag, &$eventData) {
+ global $serendipity;
+
+ $hooks = &$bag->get('event_hooks');
+
+ if (isset($hooks[$event])) {
+ switch($event) {
+ case 'frontend_display':
+ foreach ($this->markup_elements as $temp) {
+ if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) &&
+ !$eventData['properties']['ep_disable_markup_' . $this->instance] &&
+ !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) {
+ $element = $temp['element'];
+ $eventData[$element] = $this->geshi($eventData[$element]);
+ }
+ }
+ return true;
+ break;
+
+ case 'frontend_comment':
+ if (serendipity_db_bool($this->get_config('COMMENT', true))) {
+ echo '<div class="serendipity_commentDirection serendipity_comment_geshi">' . PLUGIN_EVENT_HIGHLIGHT_TRANSFORM . '</div>';
+ }
+ return true;
+ break;
+
+ default:
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ function highlightcallback($matches) {
+
+ $search = array("&amp;","&quot;", "&lt;", "&gt;","&#92;","&#39;","&nbsp;");
+ $replace = array("&","\"", "<", ">","\\","\'", " ");
+ $input_code = str_replace($search, $replace, $matches[3]);
+
+ $descriptorspec = array(
+ 0 => array("pipe", "r"), // stdin is a pipe that the child will read from
+ 1 => array("pipe", "w") // stdout is a pipe that the child will write to
+ );
+
+ $hl_cmd_str = $this->get_config('hl_bin_dir');
+ $hl_cmd_str .= ' --inline-css -f ';
+
+ if ( $this->get_config('hl_linenumbers')){
+ $hl_cmd_str .= " -l -m ";
+ $hl_cmd_str .= $this->get_config('hl_linenumberstart');
+ if ($this->get_config('hl_linenumberzeroes')){
+ $hl_cmd_str .= " -z ";
+ }
+ $hl_cmd_str .= ' -j ';
+ $hl_cmd_str .= $this->get_config('hl_linenumberlen');
+ }
+
+ if ($this->get_config('hl_tab_len')) {
+ $hl_cmd_str .= " -t ";
+ $hl_cmd_str .= $this->get_config('hl_tab_len');
+ }
+
+ if ($this->get_config('hl_wrap')>0){
+ $hl_cmd_str .= ($this->get_config('hl_wrap') == 1)? ' -V ':' -W ';
+ $hl_cmd_str .= " -J ";
+ $hl_cmd_str .= $this->get_config('hl_wrap_len');
+ }
+
+ if ($this->get_config('hl_format')>1){
+ $hl_cmd_str .= " -F ";
+ $hl_cmd_str .= $this->reformatschemes[$this->get_config('hl_format')];
+ }
+
+
+ $hl_cmd_str .= " -s ";
+ $hl_cmd_str .= $this->themes[$this->get_config('hl_theme')];
+
+
+ $lang = strtolower($matches[1]);
+ $hl_cmd_str .= " -S $lang ";
+
+ $process = proc_open($hl_cmd_str, $descriptorspec, $pipes);
+ if (is_resource($process)) {
+
+ fwrite($pipes[0], $matches[3]);
+ fclose($pipes[0]);
+
+ $output = stream_get_contents($pipes[1]);
+ fclose($pipes[1]);
+
+ // It is important that you close any pipes before calling
+ // proc_close in order to avoid a deadlock
+ proc_close($process);
+ }
+ $result='';
+ if (!strlen($output)) {
+ $result .= "<small>ERROR: Execution of highlight ($hl_cmd_str) failed or missing input. Check binary path.</small>";
+ $result .= "<pre style=\"font-size:9pt;\">";
+ $result .= $input_code;
+ $result .= "</pre>";
+
+ } else {
+ $result .= "<pre style=\"font-size:9pt;\">";
+ $result .= $output;
+ $result .= "</pre>";
+ }
+ return $result;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/support/highlight/examples/plugins/wordpress/README b/support/highlight/examples/plugins/wordpress/README
new file mode 100644
index 0000000000..f408d495a4
--- /dev/null
+++ b/support/highlight/examples/plugins/wordpress/README
@@ -0,0 +1,33 @@
+=== Highlight plugin ===
+
+This plugin uses highlight (http://www.andre-simon.de) to add syntax highlighting to WordPress.
+
+== Description ==
+
+The highlight utility converts source code of 120 programming languages to HTML
+with syntax highlighting. This plugin pipes the content of <pre>-Tags associated
+with a lng parameter to highlight, and returns the output code which is included
+in the WordPress blog entry.
+
+Usage:
+
+Paste the following in the code section of the blog editing form:
+
+<pre lang="c">#include <stdio.h>
+
+int main (void){
+ printf("This is some random code");
+ return 0;
+}</pre>
+
+Use the lang parameter to define the programming language (c, php, py, xml, etc).
+See the highlight documentation to learn all possible languages.
+See the highlight.php file for some formatting options (line numbering, code
+indentation, line wrapping etc).
+
+== Installation ==
+
+1. Install highlight (www.andre-simon.de) on your host
+2. Unzip the wp_highlight.zip file and upload the content to the
+ `/wp-content/plugins/` directory
+3. Activate the plugin
diff --git a/support/highlight/examples/plugins/wordpress/highlight.php b/support/highlight/examples/plugins/wordpress/highlight.php
new file mode 100644
index 0000000000..6b4fb4604f
--- /dev/null
+++ b/support/highlight/examples/plugins/wordpress/highlight.php
@@ -0,0 +1,140 @@
+<?php
+/*
+Plugin Name: Highlight
+Plugin URI: http://www.andre-simon.de
+Description: Plugin which uses the highlight utility to generate coloured source code
+Author: Andre Simon
+Version: 1.2
+Author URI: http://www.andre-simon.de
+
+
+This file is part of Highlight.
+
+Highlight is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Highlight is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Highlight. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+// Highlight options:
+
+$hl_options=array();
+$hl_options['hl_binary']='highlight'; // path to the highlight binary
+$hl_options['theme']='kwrite'; // set color theme
+$hl_options['linenumbers']=true;
+$hl_options['linenumber-start']=1;
+$hl_options['linenumber-zeroes']=1; // set to 1 if line numbers should be padded with zeros
+$hl_options['linenumber-length']=2;
+$hl_options['reformat-style']="gnu"; // possible values for C, C++ and Java Code: ansi, gnu, java, kr, linux
+$hl_options['replace-tabs']=4; // number of spaces which replace a tab
+$hl_options['wrap-style']=2; // 0 -> disable, 1-> wrap, 2-> wrap and indent function names
+$hl_options['wrap-line-length']=60; // if wrap-style <>0, this defines the line length before wrapping takes place
+
+class as_highlight {
+
+ var $ch_is_excerpt = false;
+ function __construct()
+ {
+ add_filter('the_content',array(&$this, 'hl_the_content_filter'),1);
+ }
+ // PHP 4 Constructor
+ function as_highlight ()
+ {
+ $this->__construct() ;
+ }
+
+ function as_highlight_code($matches){
+ global $hl_options;
+
+ $lang = preg_replace("'[^a-zA-Z]'","",$matches[1]);
+ // undo nl and p formatting
+ $input_code = $matches[2];
+ $input_code = preg_replace("'<br\s*\/?>\r?\n?'","\n",$input_code);
+ $search = array("&amp;","&quot;", "&lt;", "&gt;","&#92;","&#39;","&nbsp;");
+ $replace = array("&","\"", "<", ">","\\","\'", " ");
+ $input_code = str_replace($search, $replace, $input_code);
+
+ $descriptorspec = array(
+ 0 => array("pipe", "r"), // stdin is a pipe that the child will read from
+ 1 => array("pipe", "w") // stdout is a pipe that the child will write to
+ );
+
+ $hl_cmd_str = $hl_options['hl_binary'];
+ $hl_cmd_str .= ' --inline-css -I -f ';
+
+ if ($hl_options['linenumbers']){
+ $hl_cmd_str .= " -l -m ";
+ $hl_cmd_str .= $hl_options['linenumber-start'];
+ if ($hl_options['linenumber-zeroes']){
+ $hl_cmd_str .= " -z -j ";
+ $hl_cmd_str .= $hl_options['linenumber-length'];
+ }
+ }
+
+ if ($hl_options['replace-tabs']) {
+ $hl_cmd_str .= " -t ";
+ $hl_cmd_str .= $hl_options['replace-tabs'];
+ }
+
+ if ($hl_options['wrap-style']){
+ $hl_cmd_str .= ($hl_options['wrap-style'] == 1)? ' -V ':' -W ';
+ $hl_cmd_str .= " -J ";
+ $hl_cmd_str .= $hl_options['wrap-line-length'];
+ }
+
+ if ($hl_options['reformat-style']){
+ $hl_cmd_str .= " -F ";
+ $hl_cmd_str .= $hl_options['reformat-style'];
+ }
+
+ if ($hl_options['theme']){
+ $hl_cmd_str .= " -s ";
+ $hl_cmd_str .= $hl_options['theme'];
+ }
+
+ $hl_cmd_str .= " -S $lang ";
+
+ $process = proc_open($hl_cmd_str, $descriptorspec, $pipes);
+
+ if (is_resource($process)) {
+
+ fwrite($pipes[0], $input_code);
+ fclose($pipes[0]);
+ if (function_exists("stream_get_contents"))
+ {
+ $output = stream_get_contents($pipes[1]);
+ }
+ else
+ {
+ $output = "";
+ while (!feof($pipes[1])) $output .= fgets($pipes[1]);
+ }
+ fclose($pipes[1]);
+
+ // It is important that you close any pipes before calling
+ // proc_close in order to avoid a deadlock
+ $return_value = proc_close($process);
+ }
+ $newContent = "<pre>". $output ."</pre>";
+ return $newContent;
+ }
+
+ function hl_the_content_filter($content) {
+ return preg_replace_callback("/<pre\s+.*lang\s*=\"(.*)\">(.*)<\/pre>/siU",
+ array(&$this, "as_highlight_code"),
+ $content);
+ }
+}
+
+if (!function_exists('as_highlight'))
+ $as_highlight = new as_highlight();
+
+?>
diff --git a/support/highlight/examples/swig/README_SWIG b/support/highlight/examples/swig/README_SWIG
new file mode 100644
index 0000000000..07a10a0c01
--- /dev/null
+++ b/support/highlight/examples/swig/README_SWIG
@@ -0,0 +1,21 @@
+
+HIGHLIGHT SWIG INTERFACE GENERATION
+-----------------------------------
+
+SWIG (http://www.swig.org/) is a tool to generate interfaces for more than 10
+programming languages, inluding Python, Perl, Java and C#.
+The interface file highlight.i contains all information to generate wrapper code
+for the highlight::CodeGenerator class. The output module gives you access to
+the highlight parser from within your favorite (scripting) language.
+
+
+See the makefile how to compile Python and Perl modules:
+
+1. make python
+ make perl
+
+2. Run the test scripts
+ python testmod.py
+ perl testmod.pl
+
+See http://wiki.andre-simon.de/ for more information.
diff --git a/support/highlight/examples/swig/highlight.i b/support/highlight/examples/swig/highlight.i
new file mode 100644
index 0000000000..ec17c4494c
--- /dev/null
+++ b/support/highlight/examples/swig/highlight.i
@@ -0,0 +1,13 @@
+%module highlight
+%include stl.i
+%include std_string.i
+%apply const std::string& { const string& };
+%apply std::string { string };
+
+%{
+#include "../../src/core/codegenerator.h"
+%}
+
+%include "../../src/core/enums.h"
+%include "../../src/core/languagedefinition.h"
+%include "../../src/core/codegenerator.h"
diff --git a/support/highlight/examples/swig/makefile b/support/highlight/examples/swig/makefile
new file mode 100644
index 0000000000..3c4a73cd7d
--- /dev/null
+++ b/support/highlight/examples/swig/makefile
@@ -0,0 +1,34 @@
+
+CXX=g++
+CFLAGS=-g -O2 -fPIC
+
+HL_SRC=../../src/
+
+PYTHON_INC=/usr/include/python2.5/
+
+PERL_INC=`perl -MExtUtils::Embed -eperl_inc`
+
+lib-stamp:
+ make -C ${HL_SRC} -f ./makefile clean
+ make -C ${HL_SRC} -f ./makefile CFLAGS="${CFLAGS}" libhighlight.a
+ touch $@
+
+python: lib-stamp
+ swig -c++ -python -o highlight_wrap.cpp highlight.i
+ ${CXX} ${CFLAGS} -c highlight_wrap.cpp -I${PYTHON_INC} -I${HL_SRC}
+ ${CXX} -shared -s highlight_wrap.o -L${HL_SRC} -lhighlight -o _highlight.so
+
+perl: lib-stamp
+ swig -c++ -perl -o highlight_wrap.cpp highlight.i
+ ${CXX} ${CFLAGS} -c highlight_wrap.cpp ${PERL_INC} -I${HL_SRC}
+ ${CXX} -shared -s highlight_wrap.o -L${HL_SRC} -lhighlight -o highlight.so
+
+
+clean: python-clean perl-clean
+ rm *-stamp
+
+perl-clean:
+ rm -f highlight.so highlight_wrap.cpp highlight.pm *.o
+
+
+.PHONY: python python-clean perl perl-clean clean
diff --git a/support/highlight/examples/swig/testmod.pl b/support/highlight/examples/swig/testmod.pl
new file mode 100644
index 0000000000..7d2aa474d5
--- /dev/null
+++ b/support/highlight/examples/swig/testmod.pl
@@ -0,0 +1,28 @@
+# Perl SWIG module test script
+#
+# Import highlight.pm, which is the interface for the highlight.so module.
+# See highlight.pm for all available attributes and class members.
+
+use highlight;
+
+#get a generator instance (for HTML output)
+my $gen = highlightc::CodeGenerator_getInstance($highlightc::HTML);
+
+
+#initialize the generator with a colour theme and the language definition
+$gen->initTheme("/usr/share/highlight/themes/kwrite.style");
+$gen->loadLanguage("/usr/share/highlight/langDefs/c.lang");
+
+#set some parameters
+$gen->setIncludeStyle(1);
+$gen->setEncoding("ISO-8859-1");
+
+#get output string
+my $output=$gen->generateString("int main(int argc, char **argv) {\n".
+ " HighlightApp app;\n".
+ " return app.run(argc, argv);\n".
+ "}\n");
+print $output;
+
+# clear the instance
+highlightc::CodeGenerator_deleteInstance($gen);
diff --git a/support/highlight/examples/swig/testmod.py b/support/highlight/examples/swig/testmod.py
new file mode 100644
index 0000000000..bcaae30264
--- /dev/null
+++ b/support/highlight/examples/swig/testmod.py
@@ -0,0 +1,88 @@
+# -*- coding: utf-8 -*-
+# More advanced SWIG module test script
+#
+# Import highlight.py, which is the interface for the _highlight.so module.
+# See highlight.py for all available attributes and class members.
+#
+# Example: swig_cli.py testmod.py testmod.py.html -l --style emacs
+
+import highlight
+import sys
+from optparse import OptionParser
+
+formatList = { "html": highlight.HTML,
+ "xhtml": highlight.XHTML,
+ "latex": highlight.LATEX,
+ "rtf": highlight.RTF,
+ "tex": highlight.TEX,
+ "ansi": highlight.ANSI,
+ "xterm256": highlight.XTERM256,
+ "svg": highlight.SVG,
+ "xml": highlight.XML
+ }
+
+HL_DIR="/usr/share/highlight"
+
+def highlightFile():
+
+ parser = OptionParser("usage: %prog [options] input-file output-file")
+ parser.add_option("-O", "--format", default="html",
+ choices=("html","xhtml","latex","tex","rtf","ansi","xterm256","svg","xml"),
+ help="Output format (html, xhtml, latex, tex, rtf, ansi, xterm256, svg, xml)")
+ parser.add_option("-d", "--doc-title", default="Source file",
+ help="document title")
+ parser.add_option("-f", "--fragment", action="store_true",
+ help="omit file header and footer")
+ parser.add_option("-F", "--reformat",
+ choices=('allman','gnu','java','kr','linux', 'banner','stroustrup','whitesmith'),
+ help="reformats and indents output in given style")
+ parser.add_option("-l", "--linenumbers", action="store_true",
+ help="print line numbers in output file")
+ parser.add_option("-S", "--syntax",
+ help="specify type of source code")
+ parser.add_option("-s", "--style", default="kwrite",
+ help="defines colour style")
+ parser.add_option("-u", "--encoding", default="ISO-8859-1",
+ help="define output encoding which matches input file encoding")
+
+ (options, args) = parser.parse_args(sys.argv[1:])
+ if len(args)!=2:
+ parser.print_help()
+ return
+
+ formatName=options.format.lower()
+ outFormat = formatName in formatList and formatList[formatName] or highlight.HTML
+
+ (infile, outfile) = args
+
+ #get a generator instance (for HTML output)
+ gen=highlight.CodeGenerator_getInstance(outFormat);
+
+ #initialize the generator with a colour theme and the language definition
+ gen.initTheme("%s/themes/%s.style" % (HL_DIR, options.style));
+
+ if options.reformat:
+ gen.initIndentationScheme(options.reformat)
+
+ if (options.syntax):
+ syntax = options.syntax
+ else:
+ syntax = infile[infile.rindex(".")+1:]
+
+ gen.loadLanguage("%s/langDefs/%s.lang"% (HL_DIR, syntax))
+
+ gen.setIncludeStyle(1);
+ gen.setTitle(options.doc_title)
+ gen.setFragmentCode(options.fragment)
+ gen.setPrintLineNumbers(options.linenumbers)
+ gen.setEncoding(options.encoding);
+
+ gen.generateFile(infile, outfile)
+
+ # clear the instance
+ highlight.CodeGenerator_deleteInstance(gen);
+
+###############################################################################
+if __name__ == "__main__":
+ highlightFile()
+