A Markdown editor field for EasyAdmin, powered by the EasyMDE JavaScript editor.
It provides a MarkdownEditorField that behaves like EasyAdmin's built-in
TextEditorField (which uses Trix), but lets your users write Markdown with
a live preview, a toolbar and keyboard shortcuts. On the detail page the stored
Markdown is rendered as sanitized HTML.
| PHP | >= 8.2 |
| Symfony | 7.x and 8.x |
| EasyAdmin | 4.x and 5.x |
| Asset pipeline | AssetMapper (no build step required) |
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
composer require clementtalleu/easyadmin-markdown-bundleIf your application uses Symfony Flex, the bundle is enabled
automatically. Otherwise, enable it by hand in config/bundles.php:
// config/bundles.php
return [
// ...
ClementTalleu\EasyAdminMarkdownBundle\ClementTalleuEasyAdminMarkdownBundle::class => ['all' => true],
];The bundle never ships third-party JavaScript itself, so you add EasyMDE to your application's importmap. Use the self-contained build (it bundles CodeMirror and marked), which works reliably with AssetMapper:
php bin/console importmap:require easymde/dist/easymde.min.js
php bin/console importmap:require easymde/dist/easymde.min.cssThat's it — the field automatically loads its own JavaScript (as an ES module)
and stylesheet from the bundle, and the editor resolves EasyMDE from your
importmap. No importmap.php editing is required.
To render the Markdown as HTML on the detail page, install a Markdown parser:
composer require league/commonmarkIf you skip this step, the detail page falls back to displaying the raw Markdown source as plain text.
Use the field in any EasyAdmin CRUD controller, exactly like the native fields:
use ClementTalleu\EasyAdminMarkdownBundle\Field\MarkdownEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
class ArticleCrudController extends AbstractCrudController
{
public function configureFields(string $pageName): iterable
{
yield MarkdownEditorField::new('content');
}
}Sets the initial height (in rows) of the editor when its content is empty:
MarkdownEditorField::new('content')->setNumOfRows(20);Passes any EasyMDE configuration option to the editor. The array is JSON-encoded and forwarded to the EasyMDE constructor on the client side:
MarkdownEditorField::new('content')->setEasyMdeConfig([
'hideIcons' => ['guide', 'fullscreen'],
'tabSize' => 4,
'placeholder' => 'Write your story…',
]);By default the bundle disables EasyMDE's built-in spell checker and status bar,
and does not download Font Awesome (EasyAdmin already provides icons). You can
re-enable any of these through setEasyMdeConfig().
Forces (or disables) HTML rendering on the detail page, regardless of whether
league/commonmark is installed:
MarkdownEditorField::new('content')->renderAsHtml(false); // always show raw Markdown- The field renders a standard
<textarea>whose configuration is exposed throughdata-*attributes. - A small, framework-agnostic JavaScript module (loaded through AssetMapper) scans the page and initializes EasyMDE on each editor — the same self-contained approach EasyAdmin uses for its own Trix editor, so it does not require a Stimulus application to be running on the admin pages.
- The editor keeps the original
<textarea>in sync so the form submits the Markdown source and EasyAdmin's "unsaved changes" detection keeps working. - Required fields are validated client-side even though EasyMDE hides the original textarea.
- Markdown rendered on the detail page is sanitized (raw HTML is escaped and unsafe links are stripped) to prevent stored XSS.
The Markdown rendered on the detail page is converted with
league/commonmark configured with html_input: escape and
allow_unsafe_links: false. Any HTML embedded in the Markdown source is escaped
rather than executed.
composer install
vendor/bin/phpunit
vendor/bin/phpstan analyse
vendor/bin/php-cs-fixer fix --dry-run --diffThis bundle is released under the MIT license.
