2017 © Pedro Peláez
 

silverstripe-module silverstripe-markdown

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

image

undefinedoffset/silverstripe-markdown

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

  • Tuesday, September 5, 2017
  • by UndefinedOffset
  • Repository
  • 1 Watchers
  • 12 Stars
  • 627 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 3 Open issues
  • 6 Versions
  • 2 % Grown

The README.md

Markdown Editor and DBField

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., (*1)

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., (*2)

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., (*3)

<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., (*4)

To set what renderer to use, in _config.php do the following:, (*5)

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:, (*6)

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., (*7)

Note: This renderer does not support Github Flavoured Markdown., (*8)

use UndefinedOffset\Markdown\Model\FieldTypes\Markdown;

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

The Versions

05/09 2017

dev-master

9999999-dev

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

  Sources   Download

BSD-3-Clause

The Requires

 

markdown silverstripe

09/01 2017

dev-ss4-compat

dev-ss4-compat

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

  Sources   Download

BSD-3-Clause

The Requires

 

markdown silverstripe

09/01 2017

2.0.0-alpha1

2.0.0.0-alpha1

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

  Sources   Download

BSD-3-Clause

The Requires

 

markdown silverstripe

18/02 2016

0.2.2

0.2.2.0

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

  Sources   Download

BSD-3-Clause

The Requires

 

markdown silverstripe

03/09 2013

0.2.1

0.2.1.0

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

  Sources   Download

BSD-3-Clause

The Requires

 

markdown silverstripe

16/07 2013

0.2.0

0.2.0.0

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

  Sources   Download

The Requires

 

markdown silverstripe