axllent / silverstripe-gfmarkdown
使用 Parsedown 进行 GitHub Flavored Markdown 编辑和渲染
2.2.7
2023-06-02 10:21 UTC
Requires
- erusev/parsedown: ^1.6
- silverstripe/framework: ^4.0 || ^5.0
- silverstripe/vendor-plugin: ^1.0 || ^2.0
README
此模块添加了一个字段和一个数据类型,允许在 CMS 中使用 GitHub Flavored Markdown 解析器 Parsedown 进行 HTML 渲染。
它包括 Ace 编辑器 用于 CMS 编辑。
要求
- Silverstripe ^4.0 || ^5.0
安装
composer require axllent/silverstripe-gfmarkdown
用法
将 Markdown 数据类型用作字段数据类型,并在 CMS 中使用 MarkdownEditor 字段进行编辑。
- 参考 Markdown 编辑器配置。
- 参考 Markdown 渲染配置。
示例
<?php use Axllent\Gfmarkdown\Forms\MarkdownEditor; class MyPage extends Page { public static $db = array( 'MarkdownContent' => 'Markdown' ); public function getCMSFields() { $fields = parent::getCMSFields(); // If you want the Ace markdown editor in the CMS $fields->addFieldToTab('Root.Main', MarkdownEditor::create('MarkdownContent') ->setTheme('github') // set theme ->setRows(20) // set number of rows in CMS ->setWrap(false) // disable word wrapping ->setHighlightActiveLine(true) // enable line highlighting ); return $fields; } }
Silverstripe 模板
<div class="content"> $MarkdownContent <!-- Will show as rendered html --> </div>