1
0
mirror of https://github.com/flarum/core.git synced 2025-07-21 08:41:17 +02:00

Rejig formatting API. closes flarum/core#85

It works but it’s not the most pretty thing in the world. @franzliedke
Would be great if you could take a look at the whole formatting API and
work your magic on it sometime… my brain is fried!
This commit is contained in:
Toby Zerner
2015-06-04 10:48:07 +09:30
parent 9487a56d61
commit 42851f425b
8 changed files with 87 additions and 26 deletions

View File

@@ -9,6 +9,20 @@ export default class PostPreview extends Component {
var post = this.props.post;
var user = post.user();
var excerpt = post.contentPlain();
var start = 0;
if (highlight) {
var regexp = new RegExp(this.props.highlight, 'gi');
start = Math.max(0, excerpt.search(regexp) - 100);
}
excerpt = (start > 0 ? '...' : '')+excerpt.substring(start, start + 200)+(excerpt.length > start + 200 ? '...' : '');
if (highlight) {
excerpt = highlight(excerpt, regexp);
}
return m('a.post-preview', {
href: app.route.post(post),
config: m.route,
@@ -17,7 +31,7 @@ export default class PostPreview extends Component {
avatar(user), ' ',
username(user), ' ',
humanTime(post.time()), ' ',
highlight(post.excerpt(), this.props.highlight)
excerpt
]));
}
}