Don't truncate HTML if content length is less than summary size (#1125), fixes #1114

This commit is contained in:
Adam Roe
2016-10-26 00:25:56 +10:00
committed by Flavio Copes
parent afc18236c2
commit cd15b9197b
3 changed files with 7 additions and 2 deletions

View File

@@ -507,7 +507,7 @@ class Page
}
$summary = Utils::truncateHTML($content, $size);
return html_entity_decode($summary);
}

View File

@@ -188,7 +188,11 @@ abstract class Utils
*/
public static function truncateHtml($text, $length = 100, $ellipsis = '...')
{
return Truncator::truncateLetters($text, $length, $ellipsis);
if (mb_strlen($text) <= $length) {
return $text;
} else {
return Truncator::truncateLetters($text, $length, $ellipsis);
}
}
/**

View File

@@ -129,6 +129,7 @@ class UtilsTest extends \Codeception\TestCase\Test
$this->assertEquals('<p>This is a string to truncate</p>', Utils::truncateHtml('<p>This is a string to truncate</p>', 100));
$this->assertEquals('<input type="file" id="file" multiple>', Utils::truncateHtml('<input type="file" id="file" multiple />', 6));
$this->assertEquals('<ol><li>item 1 <i>so...</i></li></ol>', Utils::truncateHtml('<ol><li>item 1 <i>something</i></li><li>item 2 <strong>bold</strong></li></ol>', 10));
$this->assertEquals("<p>This is a string.</p>\n<p>It splits two lines.</p>", Utils::truncateHtml("<p>This is a string.</p>\n<p>It splits two lines.</p>", 100));
}
public function testSafeTruncateHtml()