clementtalleu / easyadmin-markdown-bundle
A Markdown editor field for EasyAdmin, powered by EasyMDE.
Package info
github.com/clementtalleu/EasyAdminMarkdownBundle
Type:symfony-bundle
pkg:composer/clementtalleu/easyadmin-markdown-bundle
Requires
- php: >=8.2
- easycorp/easyadmin-bundle: ^4.24 || ^5.0
- symfony/asset-mapper: ^7.0 || ^8.0
- symfony/form: ^7.0 || ^8.0
- symfony/framework-bundle: ^7.0 || ^8.0
- symfony/twig-bundle: ^7.0 || ^8.0
Requires (Dev)
- doctrine/doctrine-bundle: ^2.12
- doctrine/orm: ^3.0
- friendsofphp/php-cs-fixer: ^3.64
- league/commonmark: ^2.4
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-symfony: ^2.0
- phpunit/phpunit: ^11.3
- symfony/browser-kit: ^7.0 || ^8.0
- symfony/css-selector: ^7.0 || ^8.0
- symfony/phpunit-bridge: ^7.2 || ^8.0
- symfony/runtime: ^7.0
- symfony/security-bundle: ^7.0
Suggests
- league/commonmark: To render the Markdown content as HTML on the 'detail' page (^2.4).
This package is auto-updated.
Last update: 2026-06-09 22:01:58 UTC
README
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) |
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Step 1: Install the bundle
composer require clementtalleu/easyadmin-markdown-bundle
If 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], ];
Step 2: Install the EasyMDE assets
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.css
That'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.
Step 3 (optional): Enable HTML rendering on the detail page
To render the Markdown as HTML on the detail page, install a Markdown parser:
composer require league/commonmark
If you skip this step, the detail page falls back to displaying the raw Markdown source as plain text.
Usage
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'); } }
Options
setNumOfRows()
Sets the initial height (in rows) of the editor when its content is empty:
MarkdownEditorField::new('content')->setNumOfRows(20);
setEasyMdeConfig()
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().
renderAsHtml()
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
How it works
- 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.
Security
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.
Running the tests
composer install vendor/bin/phpunit vendor/bin/phpstan analyse vendor/bin/php-cs-fixer fix --dry-run --diff
License
This bundle is released under the MIT license.
