Commit cd2ba599 by Carsten Brandt

use string helper to truncate string

parent 5fedb8da
...@@ -10,6 +10,7 @@ namespace yii\apidoc\helpers; ...@@ -10,6 +10,7 @@ namespace yii\apidoc\helpers;
use cebe\jssearch\Indexer; use cebe\jssearch\Indexer;
use cebe\jssearch\tokenizer\StandardTokenizer; use cebe\jssearch\tokenizer\StandardTokenizer;
use cebe\jssearch\TokenizerInterface; use cebe\jssearch\TokenizerInterface;
use yii\helpers\StringHelper;
/** /**
* ApiIndexer indexes framework API * ApiIndexer indexes framework API
...@@ -37,10 +38,7 @@ class ApiIndexer extends Indexer ...@@ -37,10 +38,7 @@ class ApiIndexer extends Indexer
if (preg_match('~<div id="classDescription">\s*<strong>(.*?)</strong>~s', $contents, $matches)) { if (preg_match('~<div id="classDescription">\s*<strong>(.*?)</strong>~s', $contents, $matches)) {
$description = strip_tags($matches[1]); $description = strip_tags($matches[1]);
} elseif (preg_match('~<p>(.*?)</p>~s', $contents, $matches)) { } elseif (preg_match('~<p>(.*?)</p>~s', $contents, $matches)) {
$description = strip_tags($matches[1]); $description = StringHelper::truncate(strip_tags($matches[1]), 1000, '...', 'UTF-8');
if (mb_strlen($description, 'UTF-8') > 1000) { // TODO truncate by words
$description = mb_substr($description, 0, 1000, 'UTF-8') . '...';
}
} else { } else {
$description = ''; $description = '';
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment