0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 08:21:52 +00:00
- Stray xmlns attributes removed from configuration documentation
. Interlinking in configuration documentation added using Injector_PurifierLinkify
. Directives now keep track of aliases to themselves

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1225 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2007-06-24 22:22:00 +00:00
parent b19fc32a5a
commit 58064592ff
12 changed files with 151 additions and 1 deletions

4
NEWS
View File

@ -25,11 +25,15 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
- Improve Serializer DefinitionCache directory permissions checks - Improve Serializer DefinitionCache directory permissions checks
- DefinitionCache no longer throws errors when it encounters old - DefinitionCache no longer throws errors when it encounters old
serial files that do not conform to the current style serial files that do not conform to the current style
- Stray xmlns attributes removed from configuration documentation
. Rewire some test-cases to swallow errors rather than expect them . Rewire some test-cases to swallow errors rather than expect them
. HTMLDefinition printer updated with some of the new attributes . HTMLDefinition printer updated with some of the new attributes
. DefinitionCache keys reordered to reflect precedence: version number, . DefinitionCache keys reordered to reflect precedence: version number,
hash, then revision number hash, then revision number
. %Core.DefinitionCache renamed to %Cache.DefinitionImpl . %Core.DefinitionCache renamed to %Cache.DefinitionImpl
. Interlinking in configuration documentation added using
Injector_PurifierLinkify
. Directives now keep track of aliases to themselves
2.0.0, released 2007-06-20 2.0.0, released 2007-06-20
# Completely refactored HTMLModuleManager, decentralizing safety # Completely refactored HTMLModuleManager, decentralizing safety

View File

@ -22,6 +22,10 @@ error_reporting(E_ALL); // probably not possible to use E_STRICT
require_once '../library/HTMLPurifier.auto.php'; require_once '../library/HTMLPurifier.auto.php';
require_once 'library/ConfigDoc.auto.php'; require_once 'library/ConfigDoc.auto.php';
$purifier = HTMLPurifier::getInstance(array(
'AutoFormat.PurifierLinkify' => true
));
$schema = HTMLPurifier_ConfigSchema::instance(); $schema = HTMLPurifier_ConfigSchema::instance();
$style = 'plain'; // use $_GET in the future $style = 'plain'; // use $_GET in the future
$configdoc = new ConfigDoc(); $configdoc = new ConfigDoc();

View File

@ -36,6 +36,7 @@ class ConfigDoc_HTMLXSLTProcessor
// fudges for HTML backwards compatibility // fudges for HTML backwards compatibility
$out = str_replace('/>', ' />', $out); // <br /> not <br/> $out = str_replace('/>', ' />', $out); // <br /> not <br/>
$out = str_replace(' xmlns=""', '', $out); // rm unnecessary xmlns $out = str_replace(' xmlns=""', '', $out); // rm unnecessary xmlns
$out = str_replace(' xmlns="http://www.w3.org/1999/xhtml"', '', $out); // rm unnecessary xmlns
if (class_exists('Tidy')) { if (class_exists('Tidy')) {
// cleanup output // cleanup output
$config = array( $config = array(

View File

@ -50,6 +50,12 @@ class ConfigDoc_XMLSerializer_ConfigSchema extends ConfigDoc_XMLSerializer
$dom_document->createElement('name', $name) $dom_document->createElement('name', $name)
); );
$dom_aliases = $dom_document->createElement('aliases');
$dom_directive->appendChild($dom_aliases);
foreach ($info->directiveAliases as $alias) {
$dom_aliases->appendChild($dom_document->createElement('alias', $alias));
}
$dom_constraints = $dom_document->createElement('constraints'); $dom_constraints = $dom_document->createElement('constraints');
$dom_directive->appendChild($dom_constraints); $dom_directive->appendChild($dom_constraints);

View File

@ -72,8 +72,16 @@
<xsl:apply-templates /> <xsl:apply-templates />
</xsl:template> </xsl:template>
<xsl:template match="directive/name"> <xsl:template match="directive/name">
<xsl:apply-templates select="../aliases/alias" mode="anchor" />
<h3 id="{../@id}"><xsl:value-of select="../@id" /></h3> <h3 id="{../@id}"><xsl:value-of select="../@id" /></h3>
</xsl:template> </xsl:template>
<xsl:template match="alias" mode="anchor">
<a id="{.}"></a>
</xsl:template>
<!-- Do not pass through -->
<xsl:template match="alias"></xsl:template>
<xsl:template match="directive/constraints"> <xsl:template match="directive/constraints">
<table class="constraints"> <table class="constraints">
<xsl:apply-templates /> <xsl:apply-templates />
@ -89,8 +97,20 @@
</td> </td>
</tr> </tr>
</xsl:if> </xsl:if>
<xsl:if test="../aliases/alias">
<xsl:apply-templates select="../aliases" mode="constraints" />
</xsl:if>
</table> </table>
</xsl:template> </xsl:template>
<xsl:template match="directive/aliases" mode="constraints">
<th>Aliases:</th>
<td>
<xsl:for-each select="alias">
<xsl:if test="position()&gt;1">, </xsl:if>
<xsl:value-of select="." />
</xsl:for-each>
</td>
</xsl:template>
<xsl:template match="directive//description"> <xsl:template match="directive//description">
<div class="description"> <div class="description">
<xsl:copy-of select="div/node()" /> <xsl:copy-of select="div/node()" />

View File

@ -61,6 +61,12 @@ class HTMLPurifier_ConfigDef_Directive extends HTMLPurifier_ConfigDef
*/ */
var $aliases = array(); var $aliases = array();
/**
* Advisory list of directive aliases, i.e. other directives that
* redirect here
*/
var $directiveAliases = array();
/** /**
* Adds a description to the array * Adds a description to the array
*/ */

View File

@ -295,6 +295,7 @@ class HTMLPurifier_ConfigSchema {
$def->info[$namespace][$name] = $def->info[$namespace][$name] =
new HTMLPurifier_ConfigDef_DirectiveAlias( new HTMLPurifier_ConfigDef_DirectiveAlias(
$new_namespace, $new_name); $new_namespace, $new_name);
$def->info[$new_namespace][$new_name]->directiveAliases[] = "$namespace.$name";
} }
/** /**

View File

@ -43,7 +43,7 @@ HTMLPurifier_ConfigSchema::define(
'Technically speaking this is not actually a doctype (as it does '. 'Technically speaking this is not actually a doctype (as it does '.
'not identify a corresponding DTD), but we are using this name '. 'not identify a corresponding DTD), but we are using this name '.
'for sake of simplicity. This will override any older directives '. 'for sake of simplicity. This will override any older directives '.
'like %Core.XHTML or %HTML.Strict.' 'like %HTML.XHTML or %HTML.Strict.'
); );
HTMLPurifier_ConfigSchema::define( HTMLPurifier_ConfigSchema::define(

View File

@ -0,0 +1,63 @@
<?php
require_once 'HTMLPurifier/Injector.php';
HTMLPurifier_ConfigSchema::define(
'AutoFormat', 'PurifierLinkify', false, 'bool', '
<p>
Internal auto-formatter that converts configuration directives in
syntax <a>%Namespace.Directive</a> to links. This directive has been available
since 2.0.1.
</p>
');
HTMLPurifier_ConfigSchema::define(
'AutoFormatParam', 'PurifierLinkifyDocURL', '#%s', 'string', '
<p>
Location of configuration documentation to link to, let %s substitute
into the configuration\'s namespace and directive names sans the percent
sign. This directive has been available since 2.0.1.
</p>
');
/**
* Injector that converts configuration directive syntax %Namespace.Directive
* to links
*/
class HTMLPurifier_Injector_PurifierLinkify extends HTMLPurifier_Injector
{
var $docURL;
function prepare($config, &$context) {
parent::prepare($config, $context);
$this->docURL = $config->get('AutoFormatParam', 'PurifierLinkifyDocURL');
}
function handleText(&$token, $config, &$context) {
if (!$this->allowsElement('a')) return;
if (strpos($token->data, '%') === false) return;
$bits = preg_split('#%([a-z0-9]+\.[a-z0-9]+)#Si', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
$token = array();
// $i = index
// $c = count
// $l = is link
for ($i = 0, $c = count($bits), $l = false; $i < $c; $i++, $l = !$l) {
if (!$l) {
if ($bits[$i] === '') continue;
$token[] = new HTMLPurifier_Token_Text($bits[$i]);
} else {
$token[] = new HTMLPurifier_Token_Start('a',
array('href' => str_replace('%s', $bits[$i], $this->docURL)));
$token[] = new HTMLPurifier_Token_Text('%' . $bits[$i]);
$token[] = new HTMLPurifier_Token_End('a');
}
}
}
}
?>

View File

@ -6,6 +6,7 @@ require_once 'HTMLPurifier/Generator.php';
require_once 'HTMLPurifier/Injector/AutoParagraph.php'; require_once 'HTMLPurifier/Injector/AutoParagraph.php';
require_once 'HTMLPurifier/Injector/Linkify.php'; require_once 'HTMLPurifier/Injector/Linkify.php';
require_once 'HTMLPurifier/Injector/PurifierLinkify.php';
HTMLPurifier_ConfigSchema::define( HTMLPurifier_ConfigSchema::define(
'AutoFormat', 'Custom', array(), 'list', ' 'AutoFormat', 'Custom', array(), 'list', '

View File

@ -0,0 +1,43 @@
<?php
require_once 'HTMLPurifier/InjectorHarness.php';
require_once 'HTMLPurifier/Injector/PurifierLinkify.php';
class HTMLPurifier_Injector_PurifierLinkifyTest extends HTMLPurifier_InjectorHarness
{
function setup() {
parent::setup();
$this->config = array(
'AutoFormat.PurifierLinkify' => true,
'AutoFormatParam.PurifierLinkifyDocURL' => '#%s'
);
}
function testLinkify() {
$this->assertResult('Foobar');
$this->assertResult('20% off!');
$this->assertResult('%Core namespace (not recognized)');
$this->assertResult(
'%Namespace.Directive',
'<a href="#Namespace.Directive">%Namespace.Directive</a>'
);
$this->assertResult(
'This %Namespace.Directive thing',
'This <a href="#Namespace.Directive">%Namespace.Directive</a> thing'
);
$this->assertResult(
'<div>This %Namespace.Directive thing</div>',
'<div>This <a href="#Namespace.Directive">%Namespace.Directive</a> thing</div>'
);
$this->assertResult(
'<a>%Namespace.Directive</a>'
);
}
}
?>

View File

@ -83,6 +83,7 @@ $test_files[] = 'HTMLPurifier/HTMLModule/TidyTest.php';
$test_files[] = 'HTMLPurifier/IDAccumulatorTest.php'; $test_files[] = 'HTMLPurifier/IDAccumulatorTest.php';
$test_files[] = 'HTMLPurifier/Injector/AutoParagraphTest.php'; $test_files[] = 'HTMLPurifier/Injector/AutoParagraphTest.php';
$test_files[] = 'HTMLPurifier/Injector/LinkifyTest.php'; $test_files[] = 'HTMLPurifier/Injector/LinkifyTest.php';
$test_files[] = 'HTMLPurifier/Injector/PurifierLinkifyTest.php';
$test_files[] = 'HTMLPurifier/LanguageFactoryTest.php'; $test_files[] = 'HTMLPurifier/LanguageFactoryTest.php';
$test_files[] = 'HTMLPurifier/LanguageTest.php'; $test_files[] = 'HTMLPurifier/LanguageTest.php';
$test_files[] = 'HTMLPurifier/Lexer/DirectLexTest.php'; $test_files[] = 'HTMLPurifier/Lexer/DirectLexTest.php';