Skip to main content
Version: 4.x

Markdown editor

Introduction

The markdown editor allows you to edit and preview markdown content, as well as upload images using drag and drop.

use Filament\Forms\Components\MarkdownEditor;

MarkdownEditor::make('content')
Markdown editor

Security

By default, the editor outputs raw Markdown and HTML, and sends it to the backend. Attackers are able to intercept the value of the component and send a different raw HTML string to the backend. As such, it is important that when outputting the HTML from a Markdown editor, it is sanitized; otherwise your site may be exposed to Cross-Site Scripting (XSS) vulnerabilities.

When Filament outputs raw HTML from the database in components such as TextColumn and TextEntry, it sanitizes it to remove any dangerous JavaScript. However, if you are outputting the HTML from a Markdown editor in your own Blade view, this is your responsibility. One option is to use Filament's sanitizeHtml() helper to do this, which is the same tool we use to sanitize HTML in the components mentioned above:

{!! str($record->content)->markdown()->sanitizeHtml() !!}

Customizing the toolbar buttons

You may set the toolbar buttons for the editor using the toolbarButtons() method. The options shown here are the defaults:

use Filament\Forms\Components\MarkdownEditor;

MarkdownEditor::make('content')
->toolbarButtons([
['bold', 'italic', 'strike', 'link'],
['heading'],
['blockquote', 'codeBlock', 'bulletList', 'orderedList'],
['table', 'attachFiles'],
['undo', 'redo'],
])

Each nested array in the main array represents a group of buttons in the toolbar.

As well as allowing a static value, the toolbarButtons() method also accepts a function to dynamically calculate it. You can inject various utilities into the function as parameters.Learn more about utility injection.
UtilityTypeParameterDescription
FieldFilament\Forms\Components\Field$componentThe current field component instance.
Get functionFilament\Schemas\Components\Utilities\Get$getA function for retrieving values from the current form data. Validation is not run.
LivewireLivewire\Component$livewireThe Livewire component instance.
Eloquent model FQN?string<Illuminate\Database\Eloquent\Model>$modelThe Eloquent model FQN for the current schema.
Operationstring$operationThe current operation being performed by the schema. Usually <code>create</code>, <code>edit</code>, or <code>view</code>.
Raw statemixed$rawStateThe current value of the field, before state casts were applied. Validation is not run.
Eloquent record?Illuminate\Database\Eloquent\Model$recordThe Eloquent record for the current schema.
Statemixed$stateThe current value of the field. Validation is not run.

Uploading images to the editor

You may customize how images are uploaded using configuration methods:

use Filament\Forms\Components\MarkdownEditor;

MarkdownEditor::make('content')
->fileAttachmentsDisk('s3')
->fileAttachmentsDirectory('attachments')
As well as allowing static values, the fileAttachmentsDisk() and fileAttachmentsDirectory() methods also accept functions to dynamically calculate them. You can inject various utilities into the function as parameters.Learn more about utility injection.
UtilityTypeParameterDescription
FieldFilament\Forms\Components\Field$componentThe current field component instance.
Get functionFilament\Schemas\Components\Utilities\Get$getA function for retrieving values from the current form data. Validation is not run.
LivewireLivewire\Component$livewireThe Livewire component instance.
Eloquent model FQN?string<Illuminate\Database\Eloquent\Model>$modelThe Eloquent model FQN for the current schema.
Operationstring$operationThe current operation being performed by the schema. Usually <code>create</code>, <code>edit</code>, or <code>view</code>.
Raw statemixed$rawStateThe current value of the field, before state casts were applied. Validation is not run.
Eloquent record?Illuminate\Database\Eloquent\Model$recordThe Eloquent record for the current schema.
Statemixed$stateThe current value of the field. Validation is not run.