diff --git a/TODO b/TODO
index dd359c0e..aff5e526 100644
--- a/TODO
+++ b/TODO
@@ -46,7 +46,7 @@ TODO List
# Formatters for plaintext
- Smileys
- Linkification for HTML Purifier docs: notably configuration and classes
- - Standardize token armor for all areas of armor
+ - Standardize token armor for all areas of processing
- Fixes for Firefox's inability to handle COL alignment props (Bug 915)
- Automatically add non-breaking spaces to empty table cells when
empty-cells:show is applied to have compatibility with Internet Explorer
diff --git a/library/HTMLPurifier/ConfigSchema.php b/library/HTMLPurifier/ConfigSchema.php
index eb5d3b2c..27b45c16 100644
--- a/library/HTMLPurifier/ConfigSchema.php
+++ b/library/HTMLPurifier/ConfigSchema.php
@@ -67,7 +67,8 @@ class HTMLPurifier_ConfigSchema {
$this->defineNamespace('URI', 'Features regarding Uniform Resource Identifiers.');
$this->defineNamespace('HTML', 'Configuration regarding allowed HTML.');
$this->defineNamespace('CSS', 'Configuration regarding allowed CSS.');
- $this->defineNamespace('AutoFormat', 'Configuration regarding auto-formatting functionality such as auto-paragraphing or linkification.');
+ $this->defineNamespace('AutoFormat', 'Configuration for activating auto-formatting functionality (also known as Injector
s)');
+ $this->defineNamespace('AutoFormatParam', 'Configuration for customizing auto-formatting functionality');
$this->defineNamespace('Output', 'Configuration relating to the generation of (X)HTML.');
$this->defineNamespace('Cache', 'Configuration for DefinitionCache and related subclasses.');
$this->defineNamespace('Test', 'Developer testing configuration for our unit tests.');
diff --git a/library/HTMLPurifier/Strategy/MakeWellFormed.php b/library/HTMLPurifier/Strategy/MakeWellFormed.php
index dda2b9e1..884632cd 100644
--- a/library/HTMLPurifier/Strategy/MakeWellFormed.php
+++ b/library/HTMLPurifier/Strategy/MakeWellFormed.php
@@ -7,6 +7,17 @@ require_once 'HTMLPurifier/Generator.php';
require_once 'HTMLPurifier/Injector/AutoParagraph.php';
require_once 'HTMLPurifier/Injector/Linkify.php';
+HTMLPurifier_ConfigSchema::define(
+ 'AutoFormat', 'Custom', array(), 'list', '
+
+ This directive can be used to add custom auto-format injectors. + Specify an array of injector names (class name minus the prefix) + or concrete implementations. Injector class must exist. This directive + has been available since 2.0.1. +
+' +); + /** * Takes tokens makes them well-formed (balance end tags, etc.) */ @@ -48,14 +59,19 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy $this->injectors = array(); - // we need a generic way of adding injectors, and also its own - // configuration namespace - if ($config->get('AutoFormat', 'AutoParagraph')) { - $this->injectors[] = new HTMLPurifier_Injector_AutoParagraph(); + $injectors = $config->getBatch('AutoFormat'); + $custom_injectors = $injectors['Custom']; + unset($injectors['Custom']); // special case + foreach ($injectors as $injector => $b) { + $injector = "HTMLPurifier_Injector_$injector"; + if ($b) $this->injectors[] = new $injector; } - - if ($config->get('AutoFormat', 'Linkify')) { - $this->injectors[] = new HTMLPurifier_Injector_Linkify(); + foreach ($custom_injectors as $injector) { + if (is_string($injector)) { + $injector = "HTMLPurifier_Injector_$injector"; + $injector = new $injector; + } + $this->injectors[] = $injector; } // array index of the injector that resulted in an array diff --git a/tests/HTMLPurifier/Injector/AutoParagraphTest.php b/tests/HTMLPurifier/Injector/AutoParagraphTest.php new file mode 100644 index 00000000..0c64d54f --- /dev/null +++ b/tests/HTMLPurifier/Injector/AutoParagraphTest.php @@ -0,0 +1,247 @@ +config = array('AutoFormat.AutoParagraph' => true); + } + + function test() { + $this->assertResult( + 'Foobar', + 'Foobar
' + ); + + $this->assertResult( +'Par 1 +Par 1 still', +'Par 1 +Par 1 still
' + ); + + $this->assertResult( +'Par1 + +Par2', + 'Par1
Par2
' + ); + + $this->assertResult( +'Par1 + + + +Par2', + 'Par1
Par2
' + ); + + $this->assertResult( +'Par1 + +Par2', + 'Par1
Par2
' + ); + + + $this->assertResult( +'Par1 + +Par2', +'Par1 + +Par2
' + ); + + $this->assertResult( + 'Par1Par2
', + 'Par1
Par2
' + ); + + $this->assertResult( + 'Par1', + 'Par1
' + ); + + $this->assertResult( +'Par1 + +Par1' + ); + + $this->assertResult( +'Par1 + + ', +'
Par1
' + ); + $this->assertResult( +'Par1 + +Par1
Par3
' + ); + + $this->assertResult( +'Par1', + 'Par1
' + ); + + $this->assertResult( +' + +Par', + 'Par
' + ); + + $this->assertResult( +' + +Par + +', + 'Par
' + ); + + $this->assertResult( +'Par1
Par2
Par1
Par2
Par1
Par2
Par1 + +Par2', + true + ); + + $this->assertResult( +'
Foo + +Bar
Foo
Bar
Foo + +Bar
Foo
Bar
Par1 + +Par2', + '
' + ); + + $this->assertResult( +'Par1
Par2
Bar
Par1a
Par2
' + ); + + $this->assertResult( +'Par1 + +Par2', + 'Par1
Par2
' + ); + + $this->assertResult( +'Par1 + +Par2', + 'Par1
Par2
' + ); + + $this->assertResult( +'Par1
Par1 +
Par1 +
Foobar
' - ); - - $this->assertResult( -'Par 1 -Par 1 still', -'Par 1 -Par 1 still
' - ); - - $this->assertResult( -'Par1 - -Par2', - 'Par1
Par2
' - ); - - $this->assertResult( -'Par1 - - - -Par2', - 'Par1
Par2
' - ); - - $this->assertResult( -'Par1 - -Par2', - 'Par1
Par2
' - ); - - - $this->assertResult( -'Par1 - -Par2', -'Par1 - -Par2
' - ); - - $this->assertResult( - 'Par1Par2
', - 'Par1
Par2
' - ); - - $this->assertResult( - 'Par1', - 'Par1
' - ); - - $this->assertResult( -'Par1 - -Par1' - ); - - $this->assertResult( -'Par1 - - ', -'
Par1
' - ); - $this->assertResult( -'Par1 - -Par1
Par3
' - ); - - $this->assertResult( -'Par1', - 'Par1
' - ); - - $this->assertResult( -' - -Par', - 'Par
' - ); - - $this->assertResult( -' - -Par - -', - 'Par
' - ); - - $this->assertResult( -'Par1
Par2
Par1
Par2
Par1
Par2
Par1 - -Par2', - true - ); - - $this->assertResult( -'
Foo - -Bar
Foo
Bar
Foo - -Bar
Foo
Bar
Par1 - -Par2', - '
' - ); - - $this->assertResult( -'Par1
Par2
Bar
Par1a
Par2
' - ); - - $this->assertResult( -'Par1 - -Par2', - 'Par1
Par2
' - ); - - $this->assertResult( -'Par1 - -Par2', - 'Par1
Par2
' - ); - - $this->assertResult( -'Par1
Par1 -
Par1 -