This repository has been archived by the owner on May 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 942bd43
Showing
9 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# For more information about the properties used in this file, | ||
# please see the EditorConfig documentation: | ||
# http://editorconfig.org | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 4 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[{*.yml,package.json}] | ||
indent_size = 2 | ||
|
||
# The indent size used in the package.json file cannot be changed: | ||
# https://github.com/npm/npm/pull/3180#issuecomment-16336516 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) 2013, Ed Chipman | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
Redistributions in binary form must reproduce the above copyright notice, this | ||
list of conditions and the following disclaimer in the documentation and/or | ||
other materials provided with the distribution. | ||
|
||
Neither the name of the {organization} nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# 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](http://parsedown.org/). | ||
|
||
It is integrated with the [SimpleMDE Markdown Editor](https://github.com/NextStepWebs/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: | ||
|
||
```php | ||
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: | ||
|
||
```html | ||
<div class="content"> | ||
$MarkdownContent <!-- Will show as rendered html --> | ||
</div> | ||
``` | ||
|
||
## Editor limitations: | ||
SimpleMDE has some nice features such as full-page editing/preview, as well as "Side by Side" editing | ||
[see demo](http://nextstepwebs.github.io/simplemde-markdown-editor/). 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
define('MARKDOWN_MODULE_BASE', basename(dirname(__FILE__))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
class SimpleMDEEditor extends TextareaField | ||
{ | ||
/** | ||
* Returns the field holder used by templates | ||
* @return {string} HTML to be used | ||
*/ | ||
public function FieldHolder($properties=array()) | ||
{ | ||
Requirements::css('vendor/etdsolutions/simplemde-markdown-editor/simplemde.min.css'); | ||
Requirements::javascript('vendor/etdsolutions/simplemde-markdown-editor/simplemde.min.js'); | ||
Requirements::css(MARKDOWN_MODULE_BASE.'/css/editor.css'); | ||
Requirements::javascript(MARKDOWN_MODULE_BASE.'/javascript/editor.js'); | ||
return parent::FieldHolder($properties); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
class Markdown extends Text | ||
{ | ||
|
||
public static $casting=array( | ||
'AsHTML'=>'HTMLText', | ||
'Markdown'=>'Text' | ||
); | ||
|
||
|
||
public static $escape_type='xml'; | ||
|
||
/** | ||
* @return {string} Markdown rendered as HTML | ||
*/ | ||
public function AsHTML() | ||
{ | ||
$Parsedown = new Parsedown(); | ||
return $Parsedown->text($this->value); | ||
} | ||
|
||
/** | ||
* Renders the field used in the template | ||
* @return {string} HTML to be used in the template | ||
*/ | ||
public function forTemplate() | ||
{ | ||
return $this->AsHTML(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "axllent/silverstripe-simplemde-markdown", | ||
"description": "SimpleMDE editor & markdown support for SilverStripe 3", | ||
"type": "silverstripe-module", | ||
"homepage": "https://github.com/axllent/silverstripe-simplemde-markdown", | ||
"keywords": ["silverstripe", "markdown"], | ||
"license": "The MIT License (MIT)", | ||
"authors": [ | ||
{ | ||
"name": "Ralph Slooten", | ||
"homepage": "http://www.axllent.org/" | ||
} | ||
], | ||
"support": { | ||
"issues": "https://github.com/axllent/silverstripe-simplemde-markdown/issues" | ||
}, | ||
"require": { | ||
"silverstripe/cms": "3.*", | ||
"erusev/parsedown": "*", | ||
"etdsolutions/simplemde-markdown-editor": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* Some default styling so the preview function at least shows larger fonts / lists etc */ | ||
.editor-preview h1 { | ||
font-size: 24px; | ||
line-height: 24px; | ||
font-weight: bold; | ||
margin: 16px 0px; | ||
} | ||
.editor-preview ul, | ||
.editor-preview ol | ||
{ | ||
margin: 0 0 20px; | ||
padding-left: 20px; | ||
list-style: disc; | ||
} | ||
.editor-preview ol { | ||
list-style: decimal; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
(function($) { | ||
$.entwine('ss', function($) { | ||
$('textarea.simplemdeeditor').entwine({ | ||
onmatch: function() { | ||
var _self = $(this); | ||
var simplemde = new SimpleMDE({ | ||
element: document.getElementById(_self.attr('id')), | ||
hideIcons: ["side-by-side", "fullscreen"] | ||
}); | ||
simplemde.codemirror.on('change', function() { | ||
_self.val(simplemde.value()).change(); | ||
}); | ||
} | ||
}); | ||
}); | ||
})(jQuery); |