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 return '<div class="alert alert-error">'
26 . 'Cannot open process to execute rst2html'
30 fwrite($pipes[0], $file->getContent());
33 $html = stream_get_contents($pipes[1]);
36 $errors = stream_get_contents($pipes[2]);
39 $retval = proc_close($process);
41 //cheap extraction of the rst html body
42 $html = substr($html, strpos($html, '<body>') + 6);
43 $html = substr($html, 0, strpos($html, '</body>'));
46 $html = '<div class="alert">'
47 . 'rst2html encountered some error; return value '
49 . 'Error message: ' . $errors