mirror of
https://github.com/getgrav/grav.git
synced 2026-05-07 13:26:26 +02:00
This commit is contained in:
@@ -507,7 +507,7 @@ class Page
|
||||
}
|
||||
|
||||
$summary = Utils::truncateHTML($content, $size);
|
||||
|
||||
|
||||
return html_entity_decode($summary);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user