From 8bff2606d8c5fc375353399c8297a204a31fe623 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 17 Jul 2008 00:06:24 -0400 Subject: [PATCH] Factor out parse() from process(); remove unnecessary xmlns. process() is a super-method that does many things; parse() now performs the parsing of text into DOM form, stopping prior to the DOM filters. This is useful for filters that need to compose multiple XHTML documents into one. The post-processing of the HTML string now removes unnecessary xmlns from non root elements in order to ease validation. Signed-off-by: Edward Z. Yang --- XHTMLCompiler/FilterManager.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/XHTMLCompiler/FilterManager.php b/XHTMLCompiler/FilterManager.php index d61f21f..ea3f514 100644 --- a/XHTMLCompiler/FilterManager.php +++ b/XHTMLCompiler/FilterManager.php @@ -100,12 +100,13 @@ class XHTMLCompiler_FilterManager } /** - * Accepts a page's text (usually XHTML) and processes it. + * Accepts a page's text and turns it into its DOM representation. + * Text, initial validation and XIncludes will be processed before + * returning. DOM filters will *not* be processed. * @param $text String text to be processed - * @param $page XHTMLCompiler_Page representing currently processed page + * @param */ - public function process($text, $page) { - + public function parse($text, $page) { // do pre-text processing foreach ($this->preTextFilters as $filter) { $text = $filter->process($text, $page, $this); @@ -126,6 +127,18 @@ class XHTMLCompiler_FilterManager $this->analyzeXIncludes($dom); $dom->xinclude(); + return $dom; + } + + /** + * Accepts a page's text (usually XHTML) and processes it. + * @param $text String text to be processed + * @param $page XHTMLCompiler_Page representing currently processed page + */ + public function process($text, $page) { + + $dom = $this->parse($text, $page); + // run DOM filters foreach ($this->DOMFilters as $filter) { $filter->setup($dom); @@ -150,6 +163,14 @@ class XHTMLCompiler_FilterManager $text ); + // replace any redundant xmlns sections, although they are + // valid they interfere with DTD validation + $text = preg_replace( + '#(<(?!html)[^>]+) xmlns="http://www.w3.org/1999/xhtml"#', + '$1', + $text + ); + // okay, now finally do validation, and let the errors get // spit out if there are some collect parse errors set_error_handler(array($this, 'validationErrorHandler')); -- 2.11.4.GIT