3 * A simple renderer that allows downloading of code and file snippets
5 * @author Andreas Gohr <andi@splitbrain.org>
7 if(!defined('DOKU_INC')) die('meh.');
8 require_once DOKU_INC . 'inc/parser/renderer.php';
10 class Doku_Renderer_code extends Doku_Renderer {
14 * Send the wanted code block to the browser
16 * When the correct block was found it exits the script.
18 function code($text, $language = NULL, $filename='' ) {
20 if(!$language) $language = 'txt';
21 if(!$filename) $filename = 'snippet.'.$language;
22 $filename = utf8_basename($filename);
24 if($this->_codeblock == $INPUT->str('codeblock')){
25 header("Content-Type: text/plain; charset=utf-8");
26 header("Content-Disposition: attachment; filename=$filename");
27 header("X-Robots-Tag: noindex");
28 echo trim($text,"\r\n");
38 function file($text, $language = NULL, $filename='') {
39 $this->code($text, $language, $filename);
43 * This should never be reached, if it is send a 404
45 function document_end() {
46 header("HTTP/1.0 404 Not Found");
47 echo '404 - Not found';
52 * Return the format of the renderer
54 * @returns string 'code'