Skip to content

Commit 5e664a6

Browse files
authored
support markdown editor
1 parent 4d8d8fd commit 5e664a6

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

config/filament-comments.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
*/
2828
'prune_after_days' => 30,
2929

30+
31+
/*
32+
* Options: 'rich', 'markdown'
33+
*/
34+
'editor' => 'rich',
35+
3036
/*
3137
* The rich editor toolbar buttons that are available to users.
3238
*/

resources/views/comments.blade.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@
4646
</div>
4747

4848
<div class="prose dark:prose-invert [&>*]:mb-2 [&>*]:mt-0 [&>*:last-child]:mb-0 prose-sm text-sm leading-6 text-gray-950 dark:text-white">
49-
{{ Str::of($comment->comment)->toHtmlString() }}
49+
@if(config('filament-comments.editor') === 'markdown')
50+
{{ Str::of($comment->comment)->markdown()->toHtmlString() }}
51+
@else
52+
{{ Str::of($comment->comment)->toHtmlString() }}
53+
@endif
5054
</div>
5155
</div>
5256
</div>

src/Livewire/CommentsComponent.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,24 @@ public function form(Form $form): Form
3131
return $form;
3232
}
3333

34+
if (config('filament-comments.editor') === 'markdown') {
35+
$editor = Forms\Components\MarkdownEditor::make('comment')
36+
->hiddenLabel()
37+
->required()
38+
->placeholder(__('filament-comments::filament-comments.comments.placeholder'))
39+
->toolbarButtons(config('filament-comments.toolbar_buttons'));
40+
} else {
41+
$editor = Forms\Components\RichEditor::make('comment')
42+
->hiddenLabel()
43+
->required()
44+
->placeholder(__('filament-comments::filament-comments.comments.placeholder'))
45+
->extraInputAttributes(['style' => 'min-height: 6rem'])
46+
->toolbarButtons(config('filament-comments.toolbar_buttons'));
47+
}
48+
3449
return $form
3550
->schema([
36-
Forms\Components\RichEditor::make('comment')
37-
->hiddenLabel()
38-
->required()
39-
->placeholder(__('filament-comments::filament-comments.comments.placeholder'))
40-
->extraInputAttributes(['style' => 'min-height: 6rem'])
41-
->toolbarButtons(config('filament-comments.toolbar_buttons'))
51+
$editor,
4252
])
4353
->statePath('data');
4454
}

0 commit comments

Comments
 (0)