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