From fa48de33c2f6cefbac8bfec7cde75b75390d5f39 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Wed, 15 Jun 2016 19:44:15 -0700 Subject: provide syntax based [colour] highlighting on code blocks for popular languages. I'm not happy with the line height on the list elements but couldn't see where this was defaulted. This uses the syntax [code=xxx]some code snippet[/code], where xxx represents a code/language style - with about 18 builtins. --- .../Text/Highlighter/Renderer/XML.php | 104 +++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 library/Text_Highlighter/Text/Highlighter/Renderer/XML.php (limited to 'library/Text_Highlighter/Text/Highlighter/Renderer/XML.php') diff --git a/library/Text_Highlighter/Text/Highlighter/Renderer/XML.php b/library/Text_Highlighter/Text/Highlighter/Renderer/XML.php new file mode 100644 index 000000000..7b6fb2106 --- /dev/null +++ b/library/Text_Highlighter/Text/Highlighter/Renderer/XML.php @@ -0,0 +1,104 @@ + + * @copyright 2006 Stoyan Stefanov + * @license http://www.php.net/license/3_0.txt PHP License + * @version CVS: $Id$ + * @link http://pear.php.net/package/Text_Highlighter + */ + +/** + * @ignore + */ + +require_once 'Text/Highlighter/Renderer.php'; +require_once 'Text/Highlighter/Renderer/Array.php'; +require_once 'XML/Serializer.php'; + +/** + * XML renderer, based on Andrey Demenev's HTML renderer. + * + * @author Stoyan Stefanov + * @category Text + * @package Text_Highlighter + * @copyright 2006 Stoyan Stefanov + * @license http://www.php.net/license/3_0.txt PHP License + * @version Release: 0.5.0 + * @link http://pear.php.net/package/Text_Highlighter + */ + +class Text_Highlighter_Renderer_XML extends Text_Highlighter_Renderer_Array +{ + + + /** + * Options for XML_Serializer + * + * @access private + * @var array + */ + var $_serializer_options = array(); + + + /** + * Resets renderer state + * + * Descendents of Text_Highlighter call this method from the constructor, + * passing $options they get as parameter. + * + * @access protected + */ + function reset() + { + parent::reset(); + if (isset($this->_options['xml_serializer'])) { + $this->_serializer_options = $this->_options['xml_serializer']; + } + } + + + /** + * Signals that no more tokens are available + * + * @abstract + * @access public + */ + function finalize() + { + + // call parent's finalize(), then serialize array into XML + parent::finalize(); + $output = parent::getOutput(); + + $serializer = new XML_Serializer($this->_serializer_options); + $result = $serializer->serialize($output); + if ($result === true) { + $this->_output = $serializer->getSerializedData(); + } + } + + +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ + +?> -- cgit v1.2.3