Skip to content

Commit ca60603

Browse files
committed
SS4 compat: Update readme, composer.json. Add upgrade map, editorconfig and injector config
1 parent 848ad4c commit ca60603

File tree

6 files changed

+114
-54
lines changed

6 files changed

+114
-54
lines changed

.editorconfig

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# For more information about the properties used in
2+
# this file, please see the EditorConfig documentation:
3+
# http://editorconfig.org/
4+
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
indent_size = 4
9+
indent_style = space
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
trim_trailing_whitespace = false
15+
16+
[*.{yml,js,json,css,scss,eslintrc}]
17+
indent_size = 2

README.md

+55-30
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,101 @@
1-
Markdown Editor and DBField
2-
=================
1+
# Markdown Editor and DBField
32

4-
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
3+
Adds a field and a data type that allows for Markdown editing, uses a supported renderer (default is the GitHub API)
4+
to render the HTML.
55

66
## Requirements
7-
* SilverStripe 3.x
8-
* PHP Curl Support
7+
8+
* SilverStripe 4.x
9+
* PHP cURL Support
910

1011
## Installation
11-
* Download the module from here https://github.com/UndefinedOffset/silverstripe-markdown/downloads
12-
* 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
13-
* Run dev/build?flush=all to regenerate the manifest
14-
* 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
12+
13+
* Install with [composer](https://getcomposer.org): `composer require undefinedoffset/silverstripe-markdown ^2.0`
14+
* Run `dev/build?flush=all` to regenerate the manifest
1515

1616
## Usage
17+
1718
Use the Markdown data type as your fields data type, then use the MarkdownEditor field in the cms for editing.
1819

19-
###Page class:
20+
### Page class
21+
2022
```php
21-
class MyPage extends Page {
22-
public static $db=array(
23-
'MarkdownContent'=>'Markdown'
24-
);
23+
use UndefinedOffset\Markdown\Forms\MarkdownEditor;
24+
25+
class MyPage extends Page
26+
{
27+
public static $db = array(
28+
'MarkdownContent' => 'Markdown'
29+
);
2530

26-
public function getCMSFields() {
27-
$fields=parent::getCMSFields();
31+
public function getCMSFields()
32+
{
33+
$fields = parent::getCMSFields();
2834

2935
$editor = new MarkdownEditor('MarkdownContent', 'Page Content (Markdown)');
3036
$editor->setRows(15); //optional, set number of rows in CMS
3137
$editor->setWrapMode(true); //optional, turn on word wrapping
32-
$fields->addFieldToTab("Root.Main", $editor);
38+
$fields->addFieldToTab('Root.Main', $editor);
3339

3440
return $fields;
3541
}
3642
}
3743
```
3844

45+
### Template
3946

40-
###Template:
4147
```html
4248
<div class="content">
43-
$MarkdownContent <!-- Will show as rendered html -->
49+
$MarkdownContent <!-- Will show as rendered HTML -->
4450
</div>
4551
```
4652

47-
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.
53+
You may also request the markdown using Github Flavored Markdown by calling $YourField.AsHTML(true) in your template
54+
by default Github Flavored Markdown is not used just regular Markdown is used.
55+
4856
```html
4957
<div class="content">
5058
$MarkdownContent.AsHTML(true) <!-- Will render the content using Github Flavoured Markdown -->
5159
</div>
5260
```
5361

54-
###Configuration:
55-
The default renderer is the Github renderer. However, other renderers are supported.
62+
### Configuration
63+
64+
The default renderer is the GitHub renderer. However, other renderers are supported.
5665

57-
To set what renderer to use, in **_config.php** do the following:
66+
To set what renderer to use, in `_config.php` do the following:
5867

5968
```php
60-
Markdown::setRenderer('GithubMarkdownRenderer'); //Class name of any implementation of IMarkdownRenderer will work
69+
use UndefinedOffset\Markdown\Model\FieldTypes\Markdown;
70+
71+
// Fully qualified (namespaced) class name of any implementation of IMarkdownRenderer will work:
72+
Markdown::setRenderer('UndefinedOffset\\Markdown\\Renderer\\GithubMarkdownRenderer');
6173
```
6274

63-
####GithubMarkdownRenderer
75+
#### GithubMarkdownRenderer
76+
6477
The following options are available on the default GithubMarkdownRenderer:
78+
6579
```php
66-
GithubMarkdownRenderer::useBasicAuth('github username', 'github password'); //authenticate to the Github API to get 5,000 requests per hour instead of 60
67-
GithubMarkdownRenderer::setUseGFM(true); //whether or not to use Github Flavoured Markdown
80+
use UndefinedOffset\Markdown\Renderer\GitHubMarkdownRenderer;
81+
82+
// authenticate to the Github API to get 5,000 requests per hour instead of 60
83+
GithubMarkdownRenderer::useBasicAuth('github username', 'github password');
84+
// whether or not to use Github Flavoured Markdown
85+
GithubMarkdownRenderer::setUseGFM(true);
6886
```
6987

70-
####PHPMarkdownMarkdownRenderer
71-
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.
88+
#### PHPMarkdownMarkdownRenderer
89+
90+
PHPMarkdownMarkdownRenderer is simple and has no options. Use this to avoid the delay on page load the first time
91+
after editing that comes from using the Github renderer (especially if the page has many sections of markdown). You
92+
will need to install [PHP Markdown](https://github.com/michelf/php-markdown) for this to work - it can be installed
93+
with composer.
7294

7395
**Note:** This renderer does not support Github Flavoured Markdown.
96+
7497
```php
75-
Markdown::setRenderer('PHPMarkdownMarkdownRenderer');
98+
use UndefinedOffset\Markdown\Model\FieldTypes\Markdown;
99+
100+
Markdown::setRenderer('UndefinedOffset\\Markdown\\Renderer\\PHPMarkdownMarkdownRenderer');
76101
```

_config.php

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
<?php
22
define('MARKDOWN_MODULE_BASE', basename(dirname(__FILE__)));
3-
?>

_config/injector.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
Name: markdowninjector
3+
---
4+
SilverStripe\Core\Injector\Injector:
5+
Markdown:
6+
class: UndefinedOffset\Markdown\Model\FieldTypes\Markdown

composer.json

+30-23
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
{
2-
"name": "undefinedoffset/silverstripe-markdown",
3-
"description": "Adds a field and a data type that allows for Markdown editing, uses the github api to render the html",
4-
"type": "silverstripe-module",
5-
"keywords": ["silverstripe", "markdown"],
6-
"license": "BSD-3-Clause",
7-
"authors": [
8-
{
9-
"name": "Ed Chipman",
10-
"homepage": "http://www.edchipman.ca",
11-
"role": "Developer"
12-
}
13-
],
2+
"name": "undefinedoffset/silverstripe-markdown",
3+
"description": "Adds a field and a data type that allows for Markdown editing, uses the github api to render the html",
4+
"type": "silverstripe-module",
5+
"keywords": ["silverstripe", "markdown"],
6+
"license": "BSD-3-Clause",
7+
"authors": [
8+
{
9+
"name": "Ed Chipman",
10+
"homepage": "http://www.edchipman.ca",
11+
"role": "Developer"
12+
}
13+
],
1414

15-
"require":
16-
{
17-
"silverstripe/framework": "3.*",
18-
"composer/installers": "*"
19-
},
20-
"support": {
21-
"issues": "https://github.com/undefinedoffset/silverstripe-markdown/issues"
22-
},
23-
"extra": {
24-
"installer-name": "markdown"
25-
}
15+
"require": {
16+
"silverstripe/framework": "^4.0@dev",
17+
"composer/installers": "*"
18+
},
19+
"support": {
20+
"issues": "https://github.com/undefinedoffset/silverstripe-markdown/issues"
21+
},
22+
"extra": {
23+
"installer-name": "markdown",
24+
"branch-alias": {
25+
"dev-master": "2.x-dev"
26+
}
27+
},
28+
"autoload": {
29+
"psr-4": {
30+
"UndefinedOffset\\Markdown\\": "src/"
31+
}
32+
}
2633
}

upgrade.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
mappings:
2+
MarkdownEditor: UndefinedOffset\Markdown\Forms\MarkdownEditor
3+
Markdown: UndefinedOffset\Markdown\Model\FieldTypes\Markdown
4+
GithubMarkdownRenderer: UndefinedOffset\Markdown\Renderer\GithubMarkdownRenderer
5+
IMarkdownRenderer: UndefinedOffset\Markdown\Renderer\IMarkdownRenderer
6+
PHPMarkdownMarkdownRenderer: UndefinedOffset\Markdown\Renderer\PHPMarkdownMarkdownRenderer

0 commit comments

Comments
 (0)