summaryrefslogtreecommitdiff
path: root/support/highlight/examples/plugins
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/plugins
Initial commit
Diffstat (limited to 'support/highlight/examples/plugins')
-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
8 files changed, 931 insertions, 0 deletions
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();
+
+?>