Supercharged textarea with markdown preview for Silverstripe CMS
PHP JavaScript Scheme CSS
Latest commit cd9f7d7 Jul 15, 2016 @robbieaverill Revert "Remove CMS dependency"
This reverts commit 8248b6d.

README.md

Markdown capable TextareaField for Silverstripe CMS

Packagist Packagist Code quality via Scrutinizer CI Build Status

Features

  • Live preview (toggle)
  • Extendable toolbar with common markdown functions
  • Support for both regular markdown and extra functions

Screenshot

Markdown editor screenshot

Credits and Authors

Requirements

Installation

  • Use composer to install composer require robbieaverill/silverstripe-markdowntextareafield:*
  • Run /dev/build?flush=1

Instructions

You can use the MarkdownText data type for regular markdown or MarkdownTextExtra for added syntax features:

class Page extends SiteTree {

    private static $db = array(
        'MarkdownContent' => 'MarkdownTextExtra',
    );

    public function getCMSFields() {
        $fields = parent::getCMSFields();

        $markdownfield = MarkdownTextareaField::create('MarkdownContent');
        $markdownfield->enableExtra(); // Enables extra syntax support for fields live preview.

        $fields->addFieldToTab('Root.Main', $markdownfield);        
        return $fields;
    }
}

Template:

It is also possible to override/use markdown syntax in templates:

<div class="content">
    $MarkdownContent    <!-- Depending on data type used -->
</div>

<div class="content">
    $MarkdownContent.MarkdownAsHTML    <!-- Works with both data types, regular markdown -->
</div>

<div class="content">
    $MarkdownContent.MarkdownExtraAsHTML    <!-- Works with both data types, extended syntax -->
</div>

<div class="content">
    <pre>
        // Render JSON content
        $MarkdownContent.MarkdownAsJS
        // or
        $MarkdownContent.MarkdownExtraAsJS
    </pre>
</div>

Notes

  • Bug reports and ideas more than welcome.