From 7bf061541b0424b427bbbd1300e81d12190c9c54 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 3 Apr 2012 21:52:06 +0200 Subject: rST rendering is possible now --- src/phorkie/Renderer/ReStructuredText.php | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/phorkie/Renderer/ReStructuredText.php (limited to 'src/phorkie/Renderer/ReStructuredText.php') diff --git a/src/phorkie/Renderer/ReStructuredText.php b/src/phorkie/Renderer/ReStructuredText.php new file mode 100644 index 0000000..136de16 --- /dev/null +++ b/src/phorkie/Renderer/ReStructuredText.php @@ -0,0 +1,56 @@ + array('pipe', 'r'),//stdin + 1 => array('pipe', 'w'),//stdout + 2 => array('pipe', 'w') //stderr + ); + $process = proc_open('rst2html', $descriptorspec, $pipes); + if (!is_resource($process)) { + //FIXME: fallback to geshi + return $file->getContent(); + } + + fwrite($pipes[0], $file->getContent()); + fclose($pipes[0]); + + $html = stream_get_contents($pipes[1]); + fclose($pipes[1]); + + $errors = stream_get_contents($pipes[2]); + fclose($pipes[2]); + + $retval = proc_close($process); + + //cheap extraction of the rst html body + $html = substr($html, strpos($html, '') + 6); + $html = substr($html, 0, strpos($html, '')); + + if ($retval != 0) { + $html = '
' + . 'rst2html encountered some error; return value ' . $retval . '
' + . 'Error message:' . $errors + . '
' + . $html; + } + + return $html; + } +} + +?> -- cgit v1.2.3