5 * Requires cli program "rst2html" (python docutils) to be installed
7 class Renderer_ReStructuredText
10 * Converts the rST to HTML
12 * @param File $file File to render
16 public function toHtml(File $file)
18 $descriptorspec = array(
19 0 => array('pipe', 'r'),//stdin
20 1 => array('pipe', 'w'),//stdout
21 2 => array('pipe', 'w') //stderr
23 $process = proc_open('rst2html', $descriptorspec, $pipes);
24 if (!is_resource($process)) {
25 //FIXME: fallback to geshi
26 return $file->getContent();
29 fwrite($pipes[0], $file->getContent());
32 $html = stream_get_contents($pipes[1]);
35 $errors = stream_get_contents($pipes[2]);
38 $retval = proc_close($process);
40 //cheap extraction of the rst html body
41 $html = substr($html, strpos($html, '<body>') + 6);
42 $html = substr($html, 0, strpos($html, '</body>'));
45 $html = '<div class="alert">'
46 . 'rst2html encountered some error; return value ' . $retval . '<br/>'
47 . 'Error message:' . $errors