定制 undefinedoffset/silverstripe-markdown 二次开发

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

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

undefinedoffset/silverstripe-markdown

Composer 安装命令:

composer require undefinedoffset/silverstripe-markdown

包简介

Adds a field and a data type that allows for Markdown editing, uses the github api to render the html

README 文档

README

Adds a field and a data type that allows for Markdown editing, uses a supported renderer (default is the GitHub API) to render the HTML.

Requirements

  • SilverStripe 4.x
  • PHP cURL Support

Installation

  • Install with composer: composer require undefinedoffset/silverstripe-markdown ^2.0
  • Run dev/build?flush=all to regenerate the manifest

Usage

Use the Markdown data type as your fields data type, then use the MarkdownEditor field in the cms for editing.

Page class

use UndefinedOffset\Markdown\Forms\MarkdownEditor;

class MyPage extends Page
{
    public static $db = array(
        'MarkdownContent' => 'Markdown'
    );
    
    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        
        $editor = new MarkdownEditor('MarkdownContent', 'Page Content (Markdown)');
        $editor->setRows(15); //optional, set number of rows in CMS
        $editor->setWrapMode(true); //optional, turn on word wrapping
        $fields->addFieldToTab('Root.Main', $editor);
        
        return $fields;
    }
}

Template

<div class="content">
    $MarkdownContent  <!-- Will show as rendered HTML -->
</div>

You may also request the markdown using Github Flavored Markdown by calling $YourField.AsHTML(true) in your template by default Github Flavored Markdown is not used just regular Markdown is used.

<div class="content">
    $MarkdownContent.AsHTML(true)  <!-- Will render the content using Github Flavoured Markdown -->
</div>

Configuration

The default renderer is the GitHub renderer. However, other renderers are supported.

To set what renderer to use, in _config.php do the following:

use UndefinedOffset\Markdown\Model\FieldTypes\Markdown;

// Fully qualified (namespaced) class name of any implementation of IMarkdownRenderer will work:
Markdown::setRenderer('UndefinedOffset\\Markdown\\Renderer\\GithubMarkdownRenderer'); 

GithubMarkdownRenderer

The following options are available on the default GithubMarkdownRenderer:

use UndefinedOffset\Markdown\Renderer\GitHubMarkdownRenderer;

// authenticate to the Github API to get 5,000 requests per hour instead of 60
GithubMarkdownRenderer::useBasicAuth('github username', 'github password'); 
// whether or not to use Github Flavoured Markdown
GithubMarkdownRenderer::setUseGFM(true);

PHPMarkdownMarkdownRenderer

PHPMarkdownMarkdownRenderer is simple and has no options. Use this to avoid the delay on page load the first time after editing that comes from using the Github renderer (especially if the page has many sections of markdown). You will need to install PHP Markdown for this to work - it can be installed with composer.

Note: This renderer does not support Github Flavoured Markdown.

use UndefinedOffset\Markdown\Model\FieldTypes\Markdown;

Markdown::setRenderer('UndefinedOffset\\Markdown\\Renderer\\PHPMarkdownMarkdownRenderer');

统计信息

  • 总下载量: 6.45k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 12
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 12
  • Watchers: 1
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2013-10-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固