Git Product home page Git Product logo

silverstripe-simplemde-markdown's Introduction

SimpleMDE Editor & Markdown for SilverStripe 3

This module adds a field and a data type that allows for Markdown editing in the CMS, and HTML template rendering using the Github Flavoured Markdown parser Parsedown.

It is integrated with the SimpleMDE Markdown Editor for CMS editing (see "Editor limitations" below).

Requirements

  • SilverStripe 3.x

Usage

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

Page class:

class MyMarkdownPage extends Page
{
    public static $db = array(
        'MarkdownContent'=>'Markdown'
    );

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

        $editor = SimpleMDEEditor::create('MarkdownContent', 'Page Content (Markdown)');
        $fields->addFieldToTab('Root.Main', $editor);

        return $fields;
    }
}

Template:

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

.htaccess:

The JavaScript and CSS resources needed to show the editor is unfortunately installed in the vendor folder. By default, SilverStripe blocks all HTTP requests to it (note that we do not want to include the dependencies directly because we want Composer to handle those dependencies). In order to get this to work, we'll need to allow access to those resources.

Add the following line:

RewriteCond %{REQUEST_FILENAME} !\.(js|css)$

above this line:

RewriteRule ^vendor(/|$) - [F,L,NC]

so that the .htaccess file would look similar to the following:

# Deny access to potentially sensitive files and folders
RewriteCond %{REQUEST_FILENAME} !\.(js|css)$
RewriteRule ^vendor(/|$) - [F,L,NC]

RewriteRule silverstripe-cache(/|$) - [F,L,NC]
RewriteRule composer\.(json|lock) - [F,L,NC]

Editor limitations:

SimpleMDE has some nice features such as full-page editing/preview, as well as "Side by Side" editing see demo. Unfortunately this doesn't play nice with SilverStripe's CMS as the fullscreen elements are positioned statically. Rather than some ugly hacking, and until someone hopefully finds an elegant solution (pull requests please), fullscreen & side-by-side functionality has been hidden from the toolbar.

silverstripe-simplemde-markdown's People

Contributors

axllent avatar duclet avatar mlewis-everley avatar

Stargazers

 avatar

Watchers

 avatar  avatar

silverstripe-simplemde-markdown's Issues

Editor not loading

The CSS and JS for the editor lives in /vendor. However, the .htaccess file (default ones anyway), explicitly blocks directly linking to that. As such, the editor won't load.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.