1
0
mirror of https://github.com/flarum/core.git synced 2025-07-25 18:51:40 +02:00

Add unordered list formatting

This commit is contained in:
Toby Zerner
2015-02-10 17:52:13 +10:30
parent 624d3d70bb
commit 8e5cbcd196
2 changed files with 14 additions and 5 deletions

View File

@@ -35,12 +35,14 @@ class PostSerializer extends PostBasicSerializer
$user = User::current();
unset($attributes['content']);
$canEdit = $post->can($user, 'edit');
if ($post->type != 'comment') {
$attributes['content'] = $post->content;
} else {
// @todo move to a formatter class
$attributes['contentHtml'] = $post->content_html ?: '<p>'.nl2br(htmlspecialchars(trim($post->content))).'</p>';
if ($post->can($user, 'edit')) {
$attributes['contentHtml'] = $post->content_html;
if ($canEdit) {
$attributes['content'] = $post->content;
}
}
@@ -50,12 +52,12 @@ class PostSerializer extends PostBasicSerializer
}
if ($post->delete_time) {
$attributes['isHidden'] = true;
$attributes['deleteTime'] = $post->delete_time->toRFC3339String();
}
$attributes += [
'canEdit' => $post->can($user, 'edit'),
'canEdit' => $canEdit,
'canDelete' => $post->can($user, 'delete')
];

View File

@@ -11,8 +11,15 @@ class BasicFormatter
$linkify = new Linkify;
$text = $linkify->process($text, ['attr' => ['target' => '_blank']]);
$text = preg_replace_callback('/(?:^ *[-*]\s*([^\n]*)(?:\n|$)){2,}/m', function ($matches) {
return '</p><ul>'.preg_replace('/^ *[-*]\s*([^\n]*)(?:\n|$)/m', '<li>$1</li>', trim($matches[0])).'</ul><p>';
}, $text);
$text = '<p>'.preg_replace(['/[\n]{2,}/', '/\n/'], ['</p><p>', '<br>'], trim($text)).'</p>';
$text = preg_replace(array("/<p>\s*<\/p>/i", "/(?<=<p>)\s*(?:<br>)*/i", "/\s*(?:<br>)*\s*(?=<\/p>)/i"), "", $text);
$text = str_replace("<p></p>", "", $text);
return $text;
}
}