定制 clementtalleu/easyadmin-markdown-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

clementtalleu/easyadmin-markdown-bundle

Composer 安装命令:

composer require clementtalleu/easyadmin-markdown-bundle

包简介

A Markdown editor field for EasyAdmin, powered by EasyMDE.

README 文档

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.

The MarkdownEditorField in an EasyAdmin form

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 through data-* 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.

clementtalleu/easyadmin-markdown-bundle 适用场景与选型建议

clementtalleu/easyadmin-markdown-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 448 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 06 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「markdown」 「editor」 「field」 「easyadmin」 「easymde」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 clementtalleu/easyadmin-markdown-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 clementtalleu/easyadmin-markdown-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 clementtalleu/easyadmin-markdown-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 448
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 38
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-09