kartik-v/yii2-markdown
Composer 安装命令:
composer require kartik-v/yii2-markdown
包简介
Advanced Markdown editing and conversion utilities for Yii Framework 2.0
README 文档
README
yii2-markdown
This module provides Markdown Editing and Conversion utilities for Yii Framework 2.0. It implements markdown conversion using PHP Markdown Extra and PHP Smarty Pants. In addition, you can customize the flavor of Markdown, by including additional custom conversion patterns. The module also includes an enhanced customized Markdown Editor Widget for markdown editing and preview at runtime. This widget is styled using Bootstrap 3.0. View a complete demo.
Markdown
VIEW DEMO
This is a markdown converter class that uses PHP Markdown Extra and PHP SmartyPantsTypographer for processing Markdown conversion to HTML. It also supports configurable custom conversion processing of patterns for styling your own flavour of Markdown to some extent.
View examples and details or view a complete demo.
MarkdownEditor
VIEW DEMO
This is an advanced markdown input widget with configurable options. It is styled using Bootstrap 3.0. Key features available with this widget are:
- Configurable toolbar and buttons for formatting content
- Live preview of Markdown formatted text as HTML
- Maximize editor for full screen editing
- Implements PHP Markdown Extra and PHP SmartyPantsTypographer functionality as provided by the Markdown.
- Uses Bootstrap 3.0 styling wherever possible
- Allows saving/exporting of the text-editor contents as Text or HTML
- Configurable header, footer, and input options.
- Supports localization and customization of messages and content.
View examples and details or view a complete demo.
Demo
You can see a demonstration here on usage of these functions with documentation and examples.
Installation
The preferred way to install this extension is through composer.
Note: Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the
minimum-stabilitysettings for your application's composer.json.
Either run
$ php composer.phar require kartik-v/yii2-markdown "dev-master"
or add
"kartik-v/yii2-markdown": "dev-master"
to the require section of your composer.json file.
Usage
Setup Module
Add markdown to your modules section of your Yii configuration file
'modules' => [ /* other modules */ 'markdown' => [ 'class' => 'kartik\markdown\Module', ] ];
You can setup additional configuration options for the markdown module:
'modules' => [ 'markdown' => [ // the module class 'class' => 'kartik\markdown\Module', // the controller action route used for markdown editor preview 'previewAction' => '/markdown/parse/preview', // the list of custom conversion patterns for post processing 'customConversion' => [ '<table>' => '<table class="table table-bordered table-striped">' ], // whether to use PHP SmartyPantsTypographer to process Markdown output 'smartyPants' => true ] /* other modules */ ];
Markdown
use kartik\markdown\Markdown; // default call echo Markdown::convert($content); // with custom post processing echo Markdown::convert($content, ['custom' => [ '<h1>' => '<h1 class="custom-h1">', '<h2>' => '<h2 class="custom-h2">', '<p>' => Html::beginTag('p', $options), ]]);
MarkdownEditor
// add this in your view use kartik\markdown\MarkdownEditor; // usage with model echo MarkdownEditor::widget([ 'model' => $model, 'attribute' => 'markdown', ]); // usage without model echo MarkdownEditor::widget([ 'name' => 'markdown', 'value' => $value, ]);
Smarty Templates
Smarty templates can be enabled globally by setting the module params
'modules' => [ 'markdown' => [ 'class' => 'kartik\markdown\Module', 'smarty' => true, // Smarty class configuration 'smartyParams' => [], // provide Yii::$app to the Smarty template as variable 'smartyYiiApp' => true, // provide Yii::$app->params to the Smarty template as config variables 'smartyYiiParams' => true, ], /* other modules */ ];
Then define smarty in the editor
echo MarkdownEditor::widget([ 'model' => $model, 'attribute' => 'markdown', 'smarty' => true, ]);
Note that it may be unwise to enable Smarty templates globally. You can set the module property smarty to a callable function and provide RBAC features.
'modules' => [ 'markdown' => [ 'class' => 'kartik\markdown\Module', 'smarty' => function($module) { if (\Yii::$app->user->can('smarty')) { if(\Yii::$app->user->can('smartyYiiApp')) $module->smartyYiiApp=true; else $module->smartyYiiApp=false; if(\Yii::$app->user->can('smartyYiiParams')) $module->smartyYiiParams=true; else $module->smartyYiiParams=false; return true; } return false; } ], /* other modules */ ];
It may be a better option to leave smarty turned off in the config files and turn it on in the view with the widget settings.
echo MarkdownEditor::widget([ 'model' => $model, 'attribute' => 'markdown', 'smarty' => true, 'previewAction' => Url::to(['my/preview']), ]);
Then create an action in your controller and implement RBAC there. That way Smarty templates is off by default and you can turn it on and control access to it in the Controller.
class MyController extends Controller { public function actionPreview() { $module = Yii::$app->getModule('markdown'); if (\Yii::$app->user->can('smarty')) { $module->smarty = true; $module->smartyYiiApp = \Yii::$app->user->can('smartyYiiApp') ? true : false; $module->smartyYiiParams = Yii::$app->user->can('smartyYiiParams') ? true : false; } if (isset($_POST['source'])) { $output = (strlen($_POST['source']) > 0) ? Markdown::convert($_POST['source'], ['custom' => $module->customConversion]) : $_POST['nullMsg']; } echo Json::encode(HtmlPurifier::process($output)); } }
After saving the value to the database you can render it in your views with Markdown::convert(). For example if you save the Markdown field in the content column of the Post table you can use something like the following.
$content = Post::find(['page_id'=>'myPage'])->one()->content; echo HtmlPurifier::process(Markdown::convert($content, ['custom' => $module->customConversion]))
License
yii2-markdown is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.
kartik-v/yii2-markdown 适用场景与选型建议
kartik-v/yii2-markdown 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 272.52k 次下载、GitHub Stars 达 88, 最近一次更新时间为 2013 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「jquery」 「form」 「bootstrap」 「markdown」 「editor」 「extension」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kartik-v/yii2-markdown 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kartik-v/yii2-markdown 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kartik-v/yii2-markdown 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
Views for the package MedicOneSystems Livewire Datatables with Bootstrap 4
A Laravel Filament Forms slug field.
This is a laravel 4 package for the server and client side of datatables at http://datatables.net/
A jQuery augmented PHP library for creating and validating HTML forms
统计信息
- 总下载量: 272.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 91
- 点击次数: 27
- 依赖项目数: 8
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2013-12-26