From 156a6303bc4f75d3df57f45c071bc5f4768d112f Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 8 Jun 2007 02:43:11 +0000 Subject: [PATCH] Add support for custom entities. git-svn-id: http://htmlpurifier.org/svnroot@1128 48356398-32a2-884e-a903-53898d9a118a --- TODO.txt | 1 - XHTMLCompiler/FilterManager.php | 10 ++++++++-- smoketests/entities.ent | 1 + smoketests/entities.xhtml | 23 +++++++++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 smoketests/entities.ent create mode 100644 smoketests/entities.xhtml diff --git a/TODO.txt b/TODO.txt index 682e40b..51854d1 100644 --- a/TODO.txt +++ b/TODO.txt @@ -6,7 +6,6 @@ DOMFilter - SVN-related features: parsing of $Id$ (partially implemented) - Acronym/abbreviation embedded dictionary - Embedded Math with LaTeX, see MediaWiki and texvc (difficult) -- Entity substitution: i.e. &htmlpurifier.curversion -> 2.0.0 - Comments (difficult) - Temporary different base URL (sorta like AbsolutePath, but more flexible) diff --git a/XHTMLCompiler/FilterManager.php b/XHTMLCompiler/FilterManager.php index 2bf5cc9..c4c3a2f 100644 --- a/XHTMLCompiler/FilterManager.php +++ b/XHTMLCompiler/FilterManager.php @@ -122,8 +122,10 @@ class XHTMLCompiler_FilterManager $dom->preserveWhiteSpace = false; $dom->formatOutput = true; $dom->resolveExternals = true; + $dom->substituteEntities = true; // allows for custom entities too! $dom->loadXML($text); + set_error_handler(array($this, 'muteErrorHandler')); $dom->validate(); restore_error_handler(); @@ -131,8 +133,9 @@ class XHTMLCompiler_FilterManager $dom->encoding = 'UTF-8'; // override document encoding // XInclude - // todo: factor into a DOMFilter - // add xincludes to the dependency list + // todo: + // * factor into a DOMFilter + // * add xincludes to the dependency list $xpath = new DOMXPath($dom); $xpath->registerNamespace('xi', $ns = 'http://www.w3.org/2001/XInclude'); $nodes = $xpath->query('//xi:include'); @@ -192,6 +195,9 @@ class XHTMLCompiler_FilterManager // scrub out XML declaration for Internet Explorer $text = str_replace(''."\n", '', $text); + // scrub out custom DTD additions + $text = preg_replace('/(]*?) ?\[[^\]]+\]/', '\1', $text); + return $text; } diff --git a/smoketests/entities.ent b/smoketests/entities.ent new file mode 100644 index 0000000..0d466c8 --- /dev/null +++ b/smoketests/entities.ent @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/smoketests/entities.xhtml b/smoketests/entities.xhtml new file mode 100644 index 0000000..ff69df4 --- /dev/null +++ b/smoketests/entities.xhtml @@ -0,0 +1,23 @@ + + + + %entities; +]> + + + entities.html + + +

entities.html

+

+ This file tests custom entities. The following bullets should + not be empty: +

+ + + \ No newline at end of file -- 2.11.4.GIT