You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

67 lines
1.9 KiB

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