*/
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_asciidocjs extends DokuWiki_Syntax_Plugin {
public $scriptid = 0;
/**
* Get the type of syntax this plugin defines.
*
* @param none
* @return String 'substition' (i.e. 'substitution').
* @public
* @static
*/
function getType(){
return 'protected';
}
/**
* Where to sort in?
*
* @param none
* @return Integer 6.
* @public
* @static
*/
function getSort(){
return 1;
}
/**
* Connect lookup pattern to lexer.
*
* @param $aMode String The desired rendermode.
* @return none
* @public
* @see render()
*/
function connectTo($mode) {
$this->Lexer->addEntryPattern('
* The $aState parameter gives the type of pattern * which triggered the call to this method: *
* @param $aAscdoc String The asciidoc text to convert. */ function run_asciidoctor($node,$ascdoc,$save_mode) { if ($node==''){ return ''; } $html = ''; $return_value = 1; $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("pipe", "w") // stderr ); $cwd = DOKU_PLUGIN.'asciidocjs'; $env = array(); $CMD=$node." asciidoc.js ".$save_mode; $process = proc_open($CMD, $descriptorspec, $pipes, $cwd, $env); if (is_resource($process)) { // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // Any error output will be appended to /tmp/error-output.txt fwrite($pipes[0],$ascdoc); fclose($pipes[0]); $html=stream_get_contents($pipes[1]); fclose($pipes[1]); $error=stream_get_contents($pipes[2]); fclose($pipes[2]); // It is important that you close any pipes before calling // proc_close in order to avoid a deadlock $return_value = proc_close($process); } if ($return_value==0) { return $html; } else { return ""; } } /** * Handler to prepare matched data for the rendering process. * ** The $aState parameter gives the type of pattern * which triggered the call to this method: *
** The method checks for the given $aFormat and returns * FALSE when a format isn't supported. $aRenderer * contains a reference to the renderer object which is currently * handling the rendering. The contents of $aData is the * return value of the handle() method. *
* @param $aFormat String The output format to generate. * @param $aRenderer Object A reference to the renderer object. * @param $aData Array The data created by the handle() * method. * @return Boolean TRUE if rendered successfully, or * FALSE otherwise. * @public * @see handle() */ function render($mode, Doku_Renderer $renderer, $data) { if($mode == 'xhtml'){ if(is_a($renderer,'renderer_plugin_dw2pdf')){ // this is the PDF export, render simple HTML here $renderer->doc .= $this->run_asciidoctor($this->getConf('exec_node'),$data[2],$this->getConf('save_mode')); }else{ // this is normal XHTML for Browsers, be fancy here $renderer->doc .= $data[1]; } return true; } return false; } } ?>