[ Index ] |
PHP Cross Reference of DokuWiki |
[Summary view] [Print] [Text view]
1 #!/usr/bin/env php 2 <?php 3 4 use splitbrain\phpcli\CLI; 5 use splitbrain\phpcli\Options; 6 7 if (!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../') . '/'); 8 define('NOSESSION', 1); 9 require_once (DOKU_INC . 'inc/init.php'); 10 11 /** 12 * A simple commandline tool to render some DokuWiki syntax with a given 13 * renderer. 14 * 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 18 * 19 * @license GPL2 20 * @author Andreas Gohr <andi@splitbrain.org> 21 */ 22 class RenderCLI extends CLI 23 { 24 /** 25 * Register options and arguments on the given $options object 26 * 27 * @param Options $options 28 * @return void 29 */ 30 protected function setup(Options $options) 31 { 32 $options->setHelp( 33 'A simple commandline tool to render some DokuWiki syntax with a given renderer.' . 34 "\n\n" . 35 'This may not work for plugins that expect a certain environment to be ' . 36 'set up before rendering, but should work for most or even all standard ' . 37 'DokuWiki markup' 38 ); 39 $options->registerOption('renderer', 'The renderer mode to use. Defaults to xhtml', 'r', 'mode'); 40 } 41 42 /** 43 * Your main program 44 * 45 * Arguments and options have been parsed when this is run 46 * 47 * @param Options $options 48 * @throws DokuCLI_Exception 49 * @return void 50 */ 51 protected function main(Options $options) 52 { 53 $renderer = $options->getOpt('renderer', 'xhtml'); 54 55 // do the action 56 $source = stream_get_contents(STDIN); 57 $info = []; 58 $result = p_render($renderer, p_get_instructions($source), $info); 59 if (is_null($result)) throw new DokuCLI_Exception("No such renderer $renderer"); 60 echo $result; 61 } 62 } 63 64 // Main 65 $cli = new RenderCLI(); 66 $cli->run();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body