public function output(Pagemill_Data $data, Pagemill_Stream $stream) { // Create the element and attribute arrays if ($this->hasAttribute('elements')) { $elements = $data->parseVariables($this->getAttribute('elements')); } else { $elements = self::ELEMENTS; } if ($this->hasAttribute('attributes')) { $attributes = $data->parseVariables($this->getAttribute('attributes')); } else { $attributes = self::ATTRIBUTES; } if ($this->hasAttribute('xelements')) { $elements .= ($elements ? ',' : '') . $this->getAttribute('xelements'); } if ($this->hasAttribute('xattributes')) { $attributes .= ($attributes ? ',' : '') . $this->getAttribute('xattributes'); } $elementArray = array_unique(preg_split('/ *, */', $elements)); $attributeArray = array_unique(preg_split('/ *, */', $attributes)); if (in_array('*', $elementArray)) { $elementArray = array('*'); } if (in_array('*', $attributeArray) || in_array('*.*', $attributeArray)) { $attributeArray = array('*'); } $buffer = new Pagemill_Stream(true); foreach ($this->children() as $child) { $child->rawOutput($buffer, false); } $source = $buffer->clean(); $source = $data->parseVariables($source); if (!trim($source)) { return; } if ($this->getAttribute('use') == 'markdown') { require_once TYPEF_SOURCE_DIR . '/libraries/markdown.php'; $source = Markdown($source); } try { $parser = new Pagemill_Parser(); $doctype = new Pagemill_Doctype_Html(''); // Register the href and src attribute processors for URL shortcuts $doctype->registerAttribute('/href', 'Typeframe_Attribute_Url'); $doctype->registerAttribute('/src', 'Typeframe_Attribute_Url'); $tree = $parser->parse($source, $doctype); } catch (Exception $e) { $lastError = $e->getMessage(); //$stream->puts(htmlentities($source)); //$stream->puts($source); try { $xml = @Pagemill_SimpleXmlElement::LoadHtml("<div id=\"codeblock__\">{$source}</div>"); $select = $xml->select('#codeblock__'); $inner = $select[0]->innerXml(); $parser = new Pagemill_Parser(); $doctype = new Pagemill_Doctype_Html(''); $doctype->registerAttribute('/href', 'Typeframe_Attribute_Url'); $doctype->registerAttribute('/src', 'Typeframe_Attribute_Url'); $tree = $parser->parse('<pm:template>' . trim($inner) . '</pm:template>', $doctype); } catch (Exception $e) { trigger_error($lastError); trigger_error($e->getMessage()); $stream->puts(htmlentities($source)); return; } } $this->_recurseInput($tree, $stream, $elementArray, $attributeArray, $data); }
/** * Parse a template string into a tag tree for processing. * @param string $source * @param Pagemill_Doctype The doctype to use. Inferred from source if null. * @return Pagemill_Tag */ public function parseString($source, Pagemill_Doctype $doctype = null) { $parser = new Pagemill_Parser(); $tree = $parser->parse($source, $doctype); return $tree; }