clementtalleu/easyadmin-markdown-bundle
Install the Bundle
composer require clementtalleu/easyadmin-markdown-bundle
Ensure config/bundles.php includes the bundle (auto-enabled with Flex).
Add Importmap for EasyMDE
In assets/app.js (or your importmap config):
importmap.import('https://cdn.jsdelivr.net/npm/easymde/dist/easymde.min.js');
importmap.import('https://cdn.jsdelivr.net/npm/easymde/dist/easymde.min.css');
First Use Case: Replace TextEditorField
In your CRUD controller’s configureFields():
use ClementTalleu\EasyAdminMarkdownBundle\Field\MarkdownEditorField;
yield MarkdownEditorField::new('description', 'Description')
->setFormTypeOption('required', true);
src/Field/MarkdownEditorField.php (core field logic)config/packages/easy_admin_markdown.yaml (default config)assets/controllers/easyadmin-markdown-bundle.js (client-side JS hooks)Form Editing
TextEditorField with MarkdownEditorField for any text field needing Markdown.setFormTypeOptions() (e.g., toolbar buttons, preview mode):
yield MarkdownEditorField::new('content')
->setFormTypeOptions([
'config' => [
'toolbar' => ['bold', 'italic', 'heading', '|', 'preview'],
'spellChecker' => false,
],
]);
Detail Page Rendering
setTemplate():
->setTemplate('easyadmin-markdown-bundle::field/markdown_detail.html.twig')
Asset Integration
AssetMapper (no manual builds). For custom CSS/JS, extend the bundle’s asset pipeline:
// assets/controllers/easyadmin-markdown-bundle.js
document.addEventListener('DOMContentLoaded', () => {
const editor = EasyMDE.extend({
spellChecker: false,
customClass: 'my-custom-editor',
});
// ...
});
Markdown constraint (e.g., new Markdown()) to validate syntax.getSanitizedHtml() in a custom field class to adjust DOMPurify rules.config.locale. Pass via setFormTypeOptions():
->setFormTypeOptions(['config' => ['locale' => 'fr']])
Asset Loading
importmap isn’t configured.easymde.min.js and .css are in your importmap. Test with:
php bin/console assets:debug
Sanitization Overzealousness
<figure>) may be stripped in detail views.MarkdownEditorField and override sanitizeHtml():
public function sanitizeHtml(string $html): string {
$config = DOMPurify::configuration();
$config->ALLOWED_TAGS[] = 'figure';
return DOMPurify::cleanHTML($html, $config);
}
Conflict with Other Editors
.markdown-editor via CSS:
.markdown-editor { /* EasyMDE styles */ }
EasyMDE is not defined. Ensure importmap is loaded before EasyAdmin JS.Crud::new() in your controller.bin/console debug:config clement_talleu_easyadmin_markdown to inspect config.Custom Toolbar
Extend EasyMDE config via setFormTypeOptions():
->setFormTypeOptions([
'config' => [
'toolbar' => [
'bold', 'italic', 'heading', '|',
'quote', 'unordered-list', 'ordered-list', '|',
'link', 'image', 'preview', 'side-by-side', 'fullscreen',
],
],
])
Plugin Integration
Load EasyMDE plugins (e.g., EasyMDE.extend({ plugins: ['spellChecker'] })) by:
easyadmin-markdown-bundle.js:
const editor = EasyMDE.extend({
plugins: ['spellChecker'],
spellChecker: { /* options */ },
});
Server-Side Processing
Hook into onCrudAction() to process Markdown before save:
public function configureActions(Actions $actions): Actions {
$actions->add(Crud::NEW, Action::new()
->setHandler(function (EntityManagerInterface $em, $entity) {
$entity->setProcessedContent(markdown($entity->getContent()));
$em->flush();
})
);
}
How can I help you explore Laravel packages today?