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