mirror of
https://github.com/flarum/framework.git
synced 2025-05-23 15:19:56 +08:00
Fix incorrect highlighting of post excerpts
This commit is contained in:
@ -12,14 +12,14 @@ export default class PostPreview extends Component {
|
|||||||
var excerpt = post.contentPlain();
|
var excerpt = post.contentPlain();
|
||||||
var start = 0;
|
var start = 0;
|
||||||
|
|
||||||
if (highlight) {
|
if (this.props.highlight) {
|
||||||
var regexp = new RegExp(this.props.highlight, 'gi');
|
var regexp = new RegExp(this.props.highlight, 'gi');
|
||||||
start = Math.max(0, excerpt.search(regexp) - 100);
|
start = Math.max(0, excerpt.search(regexp) - 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
excerpt = (start > 0 ? '...' : '')+excerpt.substring(start, start + 200)+(excerpt.length > start + 200 ? '...' : '');
|
excerpt = (start > 0 ? '...' : '')+excerpt.substring(start, start + 200)+(excerpt.length > start + 200 ? '...' : '');
|
||||||
|
|
||||||
if (highlight) {
|
if (this.props.highlight) {
|
||||||
excerpt = highlight(excerpt, regexp);
|
excerpt = highlight(excerpt, regexp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user