From 3d491f758802dd2376dddd5d001765b940b08743 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 26 Jul 2009 19:51:58 +0200 Subject: enhanced and syntax Ignore-this: 80398f84222bec1fce56eee8f107d37a This patch enhances the code and file syntax with several new features. 1. code and file are now essentially the same and just differ in the class name. This means you now can use the file syntax with syntax highlighting as well. This also solves problems where the code to highlight already contains a tag (FS#1493) 2. a filename can be given as label for the code or file block. It is specified as second parameter after the language: ... If no highlighting is wanted, but a filename shall be given, you can use a dash as language: ... 3. when a filename was given (as shown above), the label links to a download of the code given in the code/file block. This is made possible by a new renderer in inc/parser/code.php. The basename of given filename is suggested as filename when downloading. darcs-hash:20090726175158-7ad00-969641a06ae1393a6d99207c3cd938fb67f23a71.gz --- inc/parser/code.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 inc/parser/code.php (limited to 'inc/parser/code.php') diff --git a/inc/parser/code.php b/inc/parser/code.php new file mode 100644 index 000000000..d2bcf7d42 --- /dev/null +++ b/inc/parser/code.php @@ -0,0 +1,58 @@ + + */ +if(!defined('DOKU_INC')) die('meh.'); +require_once DOKU_INC . 'inc/parser/renderer.php'; + +class Doku_Renderer_code extends Doku_Renderer { + var $_codeblock=0; + + /** + * Send the wanted code block to the browser + * + * When the correct block was found it exits the script. + */ + function code($text, $language = NULL, $filename='' ) { + if(!$language) $language = 'txt'; + if(!$filename) $filename = 'snippet.'.$language; + $filename = basename($filename); + + if($this->_codeblock == $_REQUEST['codeblock']){ + header("Content-Type: text/plain; charset=utf-8"); + header("Content-Disposition: attachment; filename=$filename"); + header("X-Robots-Tag: noindex"); + echo trim($text,"\r\n"); + exit; + } + + $this->_codeblock++; + } + + /** + * Wraps around code() + */ + function file($text) { + $this->code($text); + } + + /** + * This should never be reached, if it is send a 404 + */ + function document_end() { + header("HTTP/1.0 404 Not Found"); + echo '404 - Not found'; + exit; + } + + /** + * Return the format of the renderer + * + * @returns string 'code' + */ + function getFormat(){ + return 'code'; + } +} -- cgit v1.2.3