mirror of
https://github.com/flarum/core.git
synced 2025-07-26 03:01:22 +02:00
Add unordered list formatting
This commit is contained in:
@@ -35,12 +35,14 @@ class PostSerializer extends PostBasicSerializer
|
|||||||
$user = User::current();
|
$user = User::current();
|
||||||
|
|
||||||
unset($attributes['content']);
|
unset($attributes['content']);
|
||||||
|
|
||||||
|
$canEdit = $post->can($user, 'edit');
|
||||||
|
|
||||||
if ($post->type != 'comment') {
|
if ($post->type != 'comment') {
|
||||||
$attributes['content'] = $post->content;
|
$attributes['content'] = $post->content;
|
||||||
} else {
|
} else {
|
||||||
// @todo move to a formatter class
|
$attributes['contentHtml'] = $post->content_html;
|
||||||
$attributes['contentHtml'] = $post->content_html ?: '<p>'.nl2br(htmlspecialchars(trim($post->content))).'</p>';
|
if ($canEdit) {
|
||||||
if ($post->can($user, 'edit')) {
|
|
||||||
$attributes['content'] = $post->content;
|
$attributes['content'] = $post->content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,12 +52,12 @@ class PostSerializer extends PostBasicSerializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($post->delete_time) {
|
if ($post->delete_time) {
|
||||||
|
$attributes['isHidden'] = true;
|
||||||
$attributes['deleteTime'] = $post->delete_time->toRFC3339String();
|
$attributes['deleteTime'] = $post->delete_time->toRFC3339String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$attributes += [
|
$attributes += [
|
||||||
'canEdit' => $post->can($user, 'edit'),
|
'canEdit' => $canEdit,
|
||||||
'canDelete' => $post->can($user, 'delete')
|
'canDelete' => $post->can($user, 'delete')
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@@ -11,8 +11,15 @@ class BasicFormatter
|
|||||||
$linkify = new Linkify;
|
$linkify = new Linkify;
|
||||||
$text = $linkify->process($text, ['attr' => ['target' => '_blank']]);
|
$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 = '<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;
|
return $text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user