1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Configure the input field for markdown |
4
|
|
|
*/ |
5
|
|
|
class MarkdownTextareaField extends TextareaField |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Define the actions allowed on this field |
9
|
|
|
* @var array |
10
|
|
|
*/ |
11
|
|
|
private static $allowed_actions = array( |
|
|
|
|
12
|
|
|
'preview', |
13
|
|
|
'parse' |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var int Visible number of text lines. |
18
|
|
|
* Default on TextareaField is too small |
19
|
|
|
*/ |
20
|
|
|
protected $rows = 15; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Toggle rendering markdown with extra syntax enabled. |
24
|
|
|
* @link http://michelf.ca/projects/php-markdown/extra |
25
|
|
|
* @var boolean |
26
|
|
|
*/ |
27
|
|
|
protected $enable_extra = false; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Returns the field holder used by templates |
31
|
|
|
* |
32
|
|
|
* @param array $properties |
33
|
|
|
* @return string HTML to be used |
34
|
|
|
*/ |
35
|
|
|
public function FieldHolder($properties = array()) |
36
|
|
|
{ |
37
|
|
|
$this->extraClasses['stacked'] = 'stacked'; |
38
|
|
|
|
39
|
|
|
Requirements::css(MARKDOWN_DIR . '/templates/css/styles.css'); |
40
|
|
|
|
41
|
|
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js'); |
42
|
|
|
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js'); |
43
|
|
|
Requirements::javascript(MARKDOWN_DIR . '/thirdparty/textinputs_jquery.js'); |
44
|
|
|
Requirements::javascript(MARKDOWN_DIR . '/templates/javascript/script.js'); |
45
|
|
|
|
46
|
|
|
return parent::FieldHolder($properties); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Turn on extra syntax support |
51
|
|
|
* @return MarkdownTextareaField |
52
|
|
|
*/ |
53
|
|
|
public function enableExtra() |
54
|
|
|
{ |
55
|
|
|
$this->enable_extra = true; |
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Body for the preview iframe with just the typography styles included |
61
|
|
|
* @return string html |
|
|
|
|
62
|
|
|
*/ |
63
|
|
|
public function preview() |
64
|
|
|
{ |
65
|
|
|
Requirements::clear(); |
66
|
|
|
// Should contain text styles of the page by Silverstripe theme conventions. |
67
|
|
|
Requirements::css('themes/' . Config::inst()->get('SSViewer', 'theme') . '/css/editor.css'); |
68
|
|
|
return $this->renderWith('PreviewFrame'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Parse markdown into html |
73
|
|
|
* @return string html |
74
|
|
|
*/ |
75
|
|
|
public function parse() |
76
|
|
|
{ |
77
|
|
|
$parser = new MarkdownParser($this->request['markdown']); |
78
|
|
|
|
79
|
|
|
return ($this->enable_extra) ? $parser->parseExtra() : $parser->parse(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Get buttons described in buttons.yml and wrap them in ViewableData |
84
|
|
|
* @return ArrayList list of buttons and theyr configurations |
85
|
|
|
*/ |
86
|
|
|
public function ToolbarButtons() |
87
|
|
|
{ |
88
|
|
|
$buttons = new ArrayList(); |
89
|
|
|
|
90
|
|
|
foreach ($this->config()->get('buttons') as $button) { |
91
|
|
|
$buttons->push(new ArrayData($button)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $buttons; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.