mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-31 19:30:21 +02:00
[2.1.0] Refine autoparagraphing algorithm.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1278 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
1
NEWS
1
NEWS
@@ -17,6 +17,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
- AutoFormatters emit friendly error messages if tags or attributes they
|
- AutoFormatters emit friendly error messages if tags or attributes they
|
||||||
need are not allowed
|
need are not allowed
|
||||||
- ConfigForm's compactification of directive names is now configurable
|
- ConfigForm's compactification of directive names is now configurable
|
||||||
|
- AutoParagraph autoformatter algorithm refined after field-testing
|
||||||
. HTMLPurifier_Config->getSerial() implemented, this is extremely useful
|
. HTMLPurifier_Config->getSerial() implemented, this is extremely useful
|
||||||
for output cache invalidation
|
for output cache invalidation
|
||||||
. ConfigForm printer now can retrieve CSS and JS files as strings, in
|
. ConfigForm printer now can retrieve CSS and JS files as strings, in
|
||||||
|
@@ -96,11 +96,19 @@ class HTMLPurifier_Injector_AutoParagraph extends HTMLPurifier_Injector
|
|||||||
// this token is already paragraph, abort
|
// this token is already paragraph, abort
|
||||||
if ($token->name == 'p') return;
|
if ($token->name == 'p') return;
|
||||||
|
|
||||||
// check if this token is adjacent to the parent
|
// this token is a block level, abort
|
||||||
if ($this->inputTokens[$this->inputIndex - 1]->type != 'start') {
|
if (!$this->_isInline($token)) return;
|
||||||
|
|
||||||
|
// check if this token is adjacent to the parent token
|
||||||
|
$prev = $this->inputTokens[$this->inputIndex - 1];
|
||||||
|
if ($prev->type != 'start') {
|
||||||
// not adjacent, we can abort early
|
// not adjacent, we can abort early
|
||||||
// add lead paragraph tag if our token is inline
|
// add lead paragraph tag if our token is inline
|
||||||
if ($this->_isInline($token)) {
|
// and the previous tag was an end paragraph
|
||||||
|
if (
|
||||||
|
$prev->name == 'p' && $prev->type == 'end' &&
|
||||||
|
$this->_isInline($token)
|
||||||
|
) {
|
||||||
$token = array($this->_pStart(), $token);
|
$token = array($this->_pStart(), $token);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@@ -242,6 +242,25 @@ Par1
|
|||||||
'<p><img /> Foo</p>'
|
'<p><img /> Foo</p>'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->assertResult(
|
||||||
|
'<li>Foo <a>bar</a></li>'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertResult(
|
||||||
|
'<li><b>baz</b><a>bar</a></li>'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertResult(
|
||||||
|
'<div><div>asdf</div><b>asdf</b></div>'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertResult(
|
||||||
|
'<div><div>asdf</div>
|
||||||
|
|
||||||
|
<b>asdf</b></div>',
|
||||||
|
'<div><div>asdf</div><p><b>asdf</b></p></div>'
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testInlineRootNode() {
|
function testInlineRootNode() {
|
||||||
|
Reference in New Issue
Block a user