[25027] | 1 | #!/usr/bin/php
|
---|
| 2 | <?php
|
---|
| 3 | /**
|
---|
| 4 | * A simple commandline tool to render some DokuWiki syntax with a given
|
---|
| 5 | * renderer.
|
---|
| 6 | *
|
---|
| 7 | * This may not work for plugins that expect a certain environment to be
|
---|
| 8 | * set up before rendering, but should work for most or even all standard
|
---|
| 9 | * DokuWiki markup
|
---|
| 10 | *
|
---|
| 11 | * @license GPL2
|
---|
| 12 | * @author Andreas Gohr <[email protected]>
|
---|
| 13 | */
|
---|
| 14 | if ('cli' != php_sapi_name()) die();
|
---|
| 15 |
|
---|
| 16 | ini_set('memory_limit','128M');
|
---|
| 17 | if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
|
---|
| 18 | define('NOSESSION',1);
|
---|
| 19 | require_once(DOKU_INC.'inc/init.php');
|
---|
| 20 | require_once(DOKU_INC.'inc/common.php');
|
---|
| 21 | require_once(DOKU_INC.'inc/parserutils.php');
|
---|
| 22 | require_once(DOKU_INC.'inc/cliopts.php');
|
---|
| 23 |
|
---|
| 24 | // handle options
|
---|
| 25 | $short_opts = 'hr:';
|
---|
| 26 | $long_opts = array('help','renderer:');
|
---|
| 27 | $OPTS = Doku_Cli_Opts::getOptions(__FILE__,$short_opts,$long_opts);
|
---|
| 28 | if ( $OPTS->isError() ) {
|
---|
| 29 | fwrite( STDERR, $OPTS->getMessage() . "\n");
|
---|
| 30 | _usage();
|
---|
| 31 | exit(1);
|
---|
| 32 | }
|
---|
| 33 | $RENDERER = 'xhtml';
|
---|
| 34 | foreach ($OPTS->options as $key => $val) {
|
---|
| 35 | switch ($key) {
|
---|
| 36 | case 'h':
|
---|
| 37 | case 'help':
|
---|
| 38 | _usage();
|
---|
| 39 | exit;
|
---|
| 40 | case 'r':
|
---|
| 41 | case 'renderer':
|
---|
| 42 | $RENDERER = $val;
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | // do the action
|
---|
| 48 | $source = stream_get_contents(STDIN);
|
---|
| 49 | $info = array();
|
---|
| 50 | $result = p_render($RENDERER,p_get_instructions($source),$info);
|
---|
| 51 | if(is_null($result)) die("No such renderer $RENDERER\n");
|
---|
| 52 | echo $result;
|
---|
| 53 |
|
---|
| 54 | /**
|
---|
| 55 | * Print usage info
|
---|
| 56 | */
|
---|
| 57 | function _usage(){
|
---|
| 58 | print "Usage: render.php <options>
|
---|
| 59 |
|
---|
| 60 | Reads DokuWiki syntax from STDIN and renders it with the given renderer
|
---|
| 61 | to STDOUT
|
---|
| 62 |
|
---|
| 63 | OPTIONS
|
---|
| 64 | -h, --help show this help and exit
|
---|
| 65 | -r, --renderer <renderer> the render mode (default: xhtml)
|
---|
| 66 | ";
|
---|
| 67 | }
|
---|