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:
@@ -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')
|
||||
];
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user