1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Represents a large text field that contains HTML and Markdown content. |
4
|
|
|
* Markdown gets processed automatically to HTML in templates |
5
|
|
|
*/ |
6
|
|
|
class MarkdownText extends HTMLText |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Define the casting for field names and types |
10
|
|
|
* @var array |
11
|
|
|
*/ |
12
|
|
|
public static $casting = array( |
13
|
|
|
'MarkdownAsHTML' => 'MarkdownText', |
14
|
|
|
'MarkdownExtraAsHTML' => 'MarkdownText', |
15
|
|
|
); |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Returns Markdown content as HTML for templates |
19
|
|
|
* @return string HTML |
20
|
|
|
*/ |
21
|
|
|
public function forTemplate() |
22
|
|
|
{ |
23
|
|
|
return $this->MarkdownAsHTML(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Return Markdown content as HTML |
28
|
|
|
* @return string HTML |
29
|
|
|
*/ |
30
|
|
|
public function MarkdownAsHTML() |
31
|
|
|
{ |
32
|
|
|
$parser = new MarkdownParser($this->value); |
33
|
|
|
return $parser->parse(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Return MarkdownExtra content as HTML |
38
|
|
|
* @return string HTML |
39
|
|
|
*/ |
40
|
|
|
public function MarkdownExtraAsHTML() |
41
|
|
|
{ |
42
|
|
|
$parser = new MarkdownParser($this->value); |
43
|
|
|
return $parser->parseExtra(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Return Markdown content as JSON encoded HTML |
48
|
|
|
* @return string JSON |
49
|
|
|
*/ |
50
|
|
|
public function MarkdownAsJS() |
51
|
|
|
{ |
52
|
|
|
return Convert::raw2json($this->MarkdownAsHTML()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Return MarkdownExtra content as JSON encoded HTML |
57
|
|
|
* @return string JSON |
58
|
|
|
*/ |
59
|
|
|
public function MarkdownExtraAsJS() |
60
|
|
|
{ |
61
|
|
|
return Convert::raw2json($this->MarkdownExtraAsHTML()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Return an instance of the MarkdownTextareaField |
66
|
|
|
* @param string $title |
|
|
|
|
67
|
|
|
* @param array $params |
|
|
|
|
68
|
|
|
* @return MarkdownTextareaField |
69
|
|
|
*/ |
70
|
|
|
public function scaffoldFormField($title = null, $params = null) |
71
|
|
|
{ |
72
|
|
|
return new MarkdownTextareaField($this->name, $title); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
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.