Skip to content

Commit

Permalink
feedback: use formatter in blade templates, use post content renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Sep 18, 2023
1 parent bac74a7 commit 3eac530
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@extends('flarum.forum::email.html.notification.base')

@section('notificationContent')
{!! $html->render($translator->trans('flarum-mentions.email.group_mentioned.html.body', [
{!! $formatter->convert($translator->trans('flarum-mentions.email.group_mentioned.html.body', [
'{recipient_display_name}' => $user->display_name,
'{mentioner_display_name}' => $blueprint->post->user->display_name,
'{title}' => $blueprint->post->discussion->title,
Expand All @@ -10,5 +10,5 @@
@endsection

@section('contentPreview')
{!! $html->render($blueprint->post->content) !!}
{!! $blueprint->post->formatContent() !!}
@endsection
4 changes: 2 additions & 2 deletions extensions/mentions/views/emails/html/postMentioned.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@extends('flarum.forum::email.html.notification.base')

@section('notificationContent')
{!! $html->render($translator->trans('flarum-mentions.email.post_mentioned.html.body', [
{!! $formatter->convert($translator->trans('flarum-mentions.email.post_mentioned.html.body', [
'{recipient_display_name}' => $user->display_name,
'{replier_display_name}' => $blueprint->reply->user->display_name,
'{post_number}' => $blueprint->post->number,
Expand All @@ -11,5 +11,5 @@
@endsection

@section('contentPreview')
{!! $html->render($blueprint->reply->content) !!}
{!! $blueprint->reply->formatContent() !!}
@endsection
4 changes: 2 additions & 2 deletions extensions/mentions/views/emails/html/userMentioned.blade.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@extends('flarum.forum::email.html.notification.base')

@section('notificationContent')
{!! $html->render($translator->trans('flarum-mentions.email.user_mentioned.html.body', [
{!! $formatter->convert($translator->trans('flarum-mentions.email.user_mentioned.html.body', [
'{mentioner_display_name}' => $blueprint->post->user->display_name,
'{title}' => $blueprint->post->discussion->title,
'{url}' => $url->to('forum')->route('discussion', ['id' => $blueprint->post->discussion_id, 'near' => $blueprint->post->number])
])) !!}
@endsection

@section('contentPreview')
{!! $html->render($blueprint->post->content) !!}
{!! $blueprint->post->formatContent() !!}
@endsection
4 changes: 2 additions & 2 deletions extensions/subscriptions/views/emails/html/newPost.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@extends('flarum.forum::email.html.notification.base')

@section('notificationContent')
{!! $html->render($translator->trans('flarum-subscriptions.email.new_post.html.body', [
{!! $formatter->convert($translator->trans('flarum-subscriptions.email.new_post.html.body', [
'{recipient_display_name}' => $user->display_name,
'{poster_display_name}' => $blueprint->post->user->display_name,
'{title}' => $blueprint->post->discussion->title,
Expand All @@ -10,5 +10,5 @@
@endsection

@section('contentPreview')
{!! $html->render($blueprint->post->content) !!}
{!! $blueprint->post->formatContent() !!}
@endsection
4 changes: 2 additions & 2 deletions extensions/suspend/views/emails/html/suspended.blade.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@extends('flarum.forum::email.html.information.base')

@section('content')
{!! $html->render($translator->trans('flarum-suspend.email.suspended.html.body', [
{!! $formatter->convert($translator->trans('flarum-suspend.email.suspended.html.body', [
'{recipient_display_name}' => $user->display_name,
'{forumTitle}' => $settings->get('forum_title')
])) !!}
@endsection

@section('contentPreview')
{!! $html->render(($blueprint->user->suspend_message ?? $translator->trans('flarum-suspend.email.no_reason_given'))) !!}
{!! $formatter->convert(($blueprint->user->suspend_message ?? $translator->trans('flarum-suspend.email.no_reason_given'))) !!}
@endsection
2 changes: 1 addition & 1 deletion extensions/suspend/views/emails/html/unsuspended.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@extends('flarum.forum::email.html.information.base')

@section('content')
{!! $html->render($translator->trans('flarum-suspend.email.unsuspended.html.body', [
{!! $formatter->convert($translator->trans('flarum-suspend.email.unsuspended.html.body', [
'{recipient_display_name}' => $user->display_name,
'{forumTitle}' => $settings->get('forum_title'),
'{forum_url}' => $url->to('forum')->base(),
Expand Down
15 changes: 15 additions & 0 deletions framework/core/src/Formatter/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,19 @@ protected function configureDefaultsOnLinks(string $xml): string
return $attributes;
});
}

/**
* Converts a plain text string (with or without Markdown) to it's HTML equivalent.
*
* @param ?string $content
* @return string
*/
public function convert(?string $content): string
{
if (! $content) {
return '';
}

return $this->getRenderer()->render($this->getParser()->parse($content));
}
}
25 changes: 0 additions & 25 deletions framework/core/src/Formatter/HtmlRenderer.php

This file was deleted.

3 changes: 1 addition & 2 deletions framework/core/src/Forum/ForumServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Flarum\Extension\Event\Disabled;
use Flarum\Extension\Event\Enabled;
use Flarum\Formatter\Formatter;
use Flarum\Formatter\HtmlRenderer;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Foundation\ErrorHandling\Registry;
use Flarum\Foundation\ErrorHandling\Reporter;
Expand Down Expand Up @@ -149,7 +148,7 @@ public function boot(Container $container, Dispatcher $events, Factory $view): v
$view->share([
'translator' => $container->make(TranslatorInterface::class),
'settings' => $container->make(SettingsRepositoryInterface::class),
'html' => $container->make(HtmlRenderer::class)
'formatter' => $container->make(Formatter::class)
]);

$events->listen(
Expand Down
2 changes: 1 addition & 1 deletion framework/core/views/email/html/information/base.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@endsection

@section('content')
<p>{!! $html->render($infoContent) !!}<p>
<p>{!! $formatter->convert($infoContent) !!}<p>
<div class="content-preview">
@yield('contentPreview')
</div>
Expand Down

0 comments on commit 3eac530

Please sign in to comment.