Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/ss4-compat'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
UndefinedOffset committed May 30, 2019
2 parents e55d847 + acb2920 commit 0b14a3a
Show file tree
Hide file tree
Showing 16 changed files with 531 additions and 345 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
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

[*.md]
trim_trailing_whitespace = false

[*.{yml,js,json,css,scss,eslintrc}]
indent_size = 2
81 changes: 53 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,101 @@
Markdown Editor and DBField
=================
# 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
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 3.x
* PHP Curl Support

* SilverStripe 4.x
* PHP cURL Support

## Installation
* Download the module from here https://github.com/UndefinedOffset/silverstripe-markdown/downloads
* Extract the downloaded archive into your site root so that the destination folder is called markdown, opening the extracted folder should contain _config.php in the root along with other files/folders
* Run dev/build?flush=all to regenerate the manifest
* Upon entering the cms and using MarkdownEditor for the first time you make need to add ?flush=all to the end of the address to force the templates to regenerate

* Install with [composer](https://getcomposer.org): `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:
### Page class

```php
class MyPage extends Page {
public static $db=array(
'MarkdownContent'=>'Markdown'
);
use UndefinedOffset\Markdown\Forms\MarkdownEditor;

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

public function getCMSFields() {
$fields=parent::getCMSFields();
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);
$fields->addFieldToTab('Root.Main', $editor);

return $fields;
}
}
```

### Template

### Template:
```html
<div class="content">
$MarkdownContent <!-- Will show as rendered html -->
$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.
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.

```html
<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.
### 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:
To set what renderer to use, in `_config.php` do the following:

```php
Markdown::setRenderer('GithubMarkdownRenderer'); //Class name of any implementation of IMarkdownRenderer will work
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:

```php
GithubMarkdownRenderer::useBasicAuth('github username', 'github password'); //authenticate to the Github API to get 5,000 requests per hour instead of 60
GithubMarkdownRenderer::setUseGFM(true); //whether or not to use Github Flavoured Markdown
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](https://github.com/michelf/php-markdown) for this to work - it can be installed with composer.

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](https://github.com/michelf/php-markdown) for this to work - it can be installed
with composer.

**Note:** This renderer does not support Github Flavoured Markdown.

```php
Markdown::setRenderer('PHPMarkdownMarkdownRenderer');
use UndefinedOffset\Markdown\Model\FieldTypes\Markdown;

Markdown::setRenderer('UndefinedOffset\\Markdown\\Renderer\\PHPMarkdownMarkdownRenderer');
```
3 changes: 0 additions & 3 deletions _config.php

This file was deleted.

6 changes: 6 additions & 0 deletions _config/injector.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
Name: markdowninjector
---
SilverStripe\Core\Injector\Injector:
Markdown:
class: UndefinedOffset\Markdown\Model\FieldTypes\DBMarkdown
48 changes: 0 additions & 48 deletions code/forms/MarkdownEditor.php

This file was deleted.

111 changes: 0 additions & 111 deletions code/model/fieldtypes/Markdown.php

This file was deleted.

Loading

0 comments on commit 0b14a3a

Please sign in to comment.