From fa48de33c2f6cefbac8bfec7cde75b75390d5f39 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 15 Jun 2016 19:44:15 -0700 Subject: provide syntax based [colour] highlighting on code blocks for popular languages. I'm not happy with the line height on the list elements but couldn't see where this was defaulted. This uses the syntax [code=xxx]some code snippet[/code], where xxx represents a code/language style - with about 18 builtins. --- library/Text_Highlighter/generate.bat | 188 ++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 library/Text_Highlighter/generate.bat (limited to 'library/Text_Highlighter/generate.bat') diff --git a/library/Text_Highlighter/generate.bat b/library/Text_Highlighter/generate.bat new file mode 100644 index 000000000..3960486c1 --- /dev/null +++ b/library/Text_Highlighter/generate.bat @@ -0,0 +1,188 @@ +@echo off +rem vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: + +rem Console highlighter class generator + +rem PHP versions 4 and 5 + +rem LICENSE: This source file is subject to version 3.0 of the PHP license +rem that is available through the world-wide-web at the following URI: +rem http://www.php.net/license/3_0.txt. If you did not receive a copy of +rem the PHP License and are unable to obtain it through the web, please +rem send a note to license@php.net so we can mail you a copy immediately. + +rem @category Text +rem @package Text_Highlighter +rem @author Andrey Demenev +rem @copyright 2004 Andrey Demenev +rem @license http://www.php.net/license/3_0.txt PHP License +rem @version CVS: $Id: generate.bat,v 1.1 2007-06-03 02:35:28 ssttoo Exp $ +rem @link http://pear.php.net/package/Text_Highlighter + +set "MHL_PARAMS=" +:doshift +set "MHL_PARAMS=%MHL_PARAMS% %1" +shift +if -%1- == -- GOTO noshift +GOTO doshift +:noshift +@php_bin@ -q -d output_buffering=1 -d include_path="@php_dir@" @bin_dir@/Text/Highlighter/generate.bat %MHL_PARAMS% + +GOTO finish +message); + usage($message); +} + +$source = array(); +$dest = array(); +$dir = ''; + +$expectp = false; +$expectx = false; +$unexpectedx = false; +$unexpectedp = false; +$si = $di = 0; + +foreach ($options[0] as $option) { + switch ($option[0]) { + case 'x': + case '--xml': + $source[$si] = $option[1]; + if ($si) { + $di++; + } + $si++; + if ($expectp) { + $unexpectedx = true; + } + $expectp = true; + $expectx = false; + break; + + case 'p': + case '--php': + if ($expectx) { + $unexpectedp = true; + } + $dest[$di] = $option[1]; + $expectp = false; + $expectx = true; + break; + + case 'd': + case '--dir': + $dir = $option[1]; + break; + + case 'h': + case '--help': + usage(); + break; + } +} + + +if ($unexpectedx && !$dir) { + usage('Unexpected -x or --xml', STDERR); +} + +if ($unexpectedp) { + usage('Unexpected -p or --php', STDERR); +} + +$nsource = count($source); +$ndest = count($dest); + +if (!$nsource && !$ndest) { + $source[]='php://stdin'; + if (!$dir) { + $dest[]='php://stdout'; + } else { + $dest[] = null; + } +} elseif ($expectp && !$dir && $nsource > 1) { + usage('-x or --xml without following -p or --php', STDERR); +} elseif ($nsource == 1 && !$ndest && !$dir) { + $dest[]='php://stdout'; +} + +if ($dir && substr($dir,-1)!='/' && substr($dir,-1)!=='\\' ) { + $dir .= DIRECTORY_SEPARATOR; +} + + +foreach ($source as $i => $xmlfile) +{ + $gen = new Text_Highlighter_Generator; + $gen->setInputFile($xmlfile); + if ($gen->hasErrors()) { + break; + } + $gen->generate(); + if ($gen->hasErrors()) { + break; + } + if (isset($dest[$i])) { + $phpfile = $dest[$i]; + } else { + $phpfile = $dir . $gen->language . '.php'; + } + $gen->saveCode($phpfile); + if ($gen->hasErrors()) { + break; + } +} +if ($gen->hasErrors()) { + $errors = $gen->getErrors(); + foreach ($errors as $error) { + fwrite (STDERR, $error . "\n"); + } + exit(1); +} + +exit(0); + +function usage($message='', $file=STDOUT) +{ + $code = 0; + if ($message) { + $message .= "\n\n"; + $code = 1; + } + $message .= << tag) + -h, --help + This help +MSG; + fwrite ($file, $message); + exit($code); +} +?> +:finish -- cgit v1.2.3