2020-06-14 00:41:58 +02:00
|
|
|
#!/usr/bin/env php
|
2010-01-05 23:42:55 +01:00
|
|
|
<?php
|
2014-03-20 20:55:57 +01:00
|
|
|
|
2017-11-10 14:18:18 +01:00
|
|
|
use splitbrain\phpcli\CLI;
|
|
|
|
use splitbrain\phpcli\Options;
|
|
|
|
|
2023-08-31 14:22:35 +02:00
|
|
|
if (!defined('DOKU_INC')) define('DOKU_INC', realpath(__DIR__ . '/../') . '/');
|
2017-11-10 14:18:18 +01:00
|
|
|
define('NOSESSION', 1);
|
|
|
|
require_once(DOKU_INC . 'inc/init.php');
|
2014-03-20 20:55:57 +01:00
|
|
|
|
2010-01-05 23:42:55 +01:00
|
|
|
/**
|
|
|
|
* A simple commandline tool to render some DokuWiki syntax with a given
|
|
|
|
* renderer.
|
|
|
|
*
|
|
|
|
* This may not work for plugins that expect a certain environment to be
|
|
|
|
* set up before rendering, but should work for most or even all standard
|
|
|
|
* DokuWiki markup
|
|
|
|
*
|
|
|
|
* @license GPL2
|
2014-05-16 09:11:15 +02:00
|
|
|
* @author Andreas Gohr <andi@splitbrain.org>
|
2010-01-05 23:42:55 +01:00
|
|
|
*/
|
2023-08-30 17:05:28 +02:00
|
|
|
class RenderCLI extends CLI
|
|
|
|
{
|
2014-03-20 20:55:57 +01:00
|
|
|
/**
|
|
|
|
* Register options and arguments on the given $options object
|
|
|
|
*
|
2017-11-10 14:18:18 +01:00
|
|
|
* @param Options $options
|
2014-03-20 20:55:57 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2023-08-30 17:09:14 +02:00
|
|
|
protected function setup(Options $options)
|
|
|
|
{
|
2014-03-20 20:55:57 +01:00
|
|
|
$options->setHelp(
|
2017-11-10 14:18:18 +01:00
|
|
|
'A simple commandline tool to render some DokuWiki syntax with a given renderer.' .
|
|
|
|
"\n\n" .
|
|
|
|
'This may not work for plugins that expect a certain environment to be ' .
|
|
|
|
'set up before rendering, but should work for most or even all standard ' .
|
2014-05-16 09:11:15 +02:00
|
|
|
'DokuWiki markup'
|
2014-03-20 20:55:57 +01:00
|
|
|
);
|
|
|
|
$options->registerOption('renderer', 'The renderer mode to use. Defaults to xhtml', 'r', 'mode');
|
2010-01-05 23:42:55 +01:00
|
|
|
}
|
|
|
|
|
2014-03-20 20:55:57 +01:00
|
|
|
/**
|
|
|
|
* Your main program
|
|
|
|
*
|
|
|
|
* Arguments and options have been parsed when this is run
|
|
|
|
*
|
2017-11-10 14:18:18 +01:00
|
|
|
* @param Options $options
|
2014-03-20 20:55:57 +01:00
|
|
|
* @throws DokuCLI_Exception
|
|
|
|
* @return void
|
|
|
|
*/
|
2023-08-30 17:09:14 +02:00
|
|
|
protected function main(Options $options)
|
|
|
|
{
|
2014-03-20 20:55:57 +01:00
|
|
|
$renderer = $options->getOpt('renderer', 'xhtml');
|
2010-01-05 23:42:55 +01:00
|
|
|
|
2014-03-20 20:55:57 +01:00
|
|
|
// do the action
|
|
|
|
$source = stream_get_contents(STDIN);
|
2023-08-30 14:48:22 +02:00
|
|
|
$info = [];
|
2014-03-20 20:55:57 +01:00
|
|
|
$result = p_render($renderer, p_get_instructions($source), $info);
|
2023-08-31 14:22:35 +02:00
|
|
|
if (is_null($result)) throw new DokuCLI_Exception("No such renderer $renderer");
|
2014-03-20 20:55:57 +01:00
|
|
|
echo $result;
|
|
|
|
}
|
2010-01-05 23:42:55 +01:00
|
|
|
}
|
2014-03-20 20:55:57 +01:00
|
|
|
|
|
|
|
// Main
|
|
|
|
$cli = new RenderCLI();
|
2017-11-10 14:18:18 +01:00
|
|
|
$cli->run();
|