translation update
[dokuwiki.git] / bin / render.php
blob672993223466ba266dd8965761849b2c9163a21a
1 #!/usr/bin/php
2 <?php
3 if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__).'/../').'/');
4 define('NOSESSION', 1);
5 require_once(DOKU_INC.'inc/init.php');
8 /**
9 * A simple commandline tool to render some DokuWiki syntax with a given
10 * renderer.
12 * This may not work for plugins that expect a certain environment to be
13 * set up before rendering, but should work for most or even all standard
14 * DokuWiki markup
16 * @license GPL2
17 * @author Andreas Gohr <andi@splitbrain.org>
19 class RenderCLI extends DokuCLI {
21 /**
22 * Register options and arguments on the given $options object
24 * @param DokuCLI_Options $options
25 * @return void
27 protected function setup(DokuCLI_Options $options) {
28 $options->setHelp(
29 'A simple commandline tool to render some DokuWiki syntax with a given renderer.'.
30 "\n\n".
31 'This may not work for plugins that expect a certain environment to be '.
32 'set up before rendering, but should work for most or even all standard '.
33 'DokuWiki markup'
35 $options->registerOption('renderer', 'The renderer mode to use. Defaults to xhtml', 'r', 'mode');
38 /**
39 * Your main program
41 * Arguments and options have been parsed when this is run
43 * @param DokuCLI_Options $options
44 * @throws DokuCLI_Exception
45 * @return void
47 protected function main(DokuCLI_Options $options) {
48 $renderer = $options->getOpt('renderer', 'xhtml');
50 // do the action
51 $source = stream_get_contents(STDIN);
52 $info = array();
53 $result = p_render($renderer, p_get_instructions($source), $info);
54 if(is_null($result)) throw new DokuCLI_Exception("No such renderer $renderer");
55 echo $result;
59 // Main
60 $cli = new RenderCLI();
61 $cli->run();