diff --git a/NEWS b/NEWS index 87ea7dfe..855325a3 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier - AutoFormatters emit friendly error messages if tags or attributes they need are not allowed - ConfigForm's compactification of directive names is now configurable +- AutoParagraph autoformatter algorithm refined after field-testing . HTMLPurifier_Config->getSerial() implemented, this is extremely useful for output cache invalidation . ConfigForm printer now can retrieve CSS and JS files as strings, in diff --git a/library/HTMLPurifier/Injector/AutoParagraph.php b/library/HTMLPurifier/Injector/AutoParagraph.php index a932ece9..24ca9d5e 100644 --- a/library/HTMLPurifier/Injector/AutoParagraph.php +++ b/library/HTMLPurifier/Injector/AutoParagraph.php @@ -96,11 +96,19 @@ class HTMLPurifier_Injector_AutoParagraph extends HTMLPurifier_Injector // this token is already paragraph, abort if ($token->name == 'p') return; - // check if this token is adjacent to the parent - if ($this->inputTokens[$this->inputIndex - 1]->type != 'start') { + // this token is a block level, abort + 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 // 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); } return; diff --git a/tests/HTMLPurifier/Injector/AutoParagraphTest.php b/tests/HTMLPurifier/Injector/AutoParagraphTest.php index 07252794..441be0de 100644 --- a/tests/HTMLPurifier/Injector/AutoParagraphTest.php +++ b/tests/HTMLPurifier/Injector/AutoParagraphTest.php @@ -242,6 +242,25 @@ Par1 '

Foo

' ); + $this->assertResult( +'
  • Foo bar
  • ' + ); + + $this->assertResult( +'
  • bazbar
  • ' + ); + + $this->assertResult( +'
    asdf
    asdf
    ' + ); + + $this->assertResult( +'
    asdf
    + +asdf
    ', +'
    asdf

    asdf

    ' + ); + } function testInlineRootNode() {