1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# DDEditor Yii Extension
This extension contains a widget to render an activeTextarea to enter Markdown text.
The rendered widget contains some buttons to add markdown tags for
* Bold, italic text
* Links
* Images
* Code
* Table structure.
It is also capable of displaying dropdown lists with _additional text snippets_ for insertion.
### Requirements
* Yii 1.1.3 or above
### Installation
* Extract the release file under `protected/extensions`
### Usage
#### Include New Extension
In your `config/main.php` file, add
// autoloading model and component classes
'import'=>array(
...
'application.extensions.ddeditor.*',
...
),
#### Create the controll in a form view:
In e.g. `views/post/_form.php`, include the following code:
<?php $this->widget(
'application.extensions.ddeditor.DDEditor',
array(
'model'=>$model,
'attribute'=>'content',
'htmlOptions'=>array('rows'=>10, 'cols'=>70),
'previewRequest'=>'post/preview')); ?>
If you want to display an **extra dropdown list** with **snippets**, you may add the
_additionalSnippets_ parameter:
<?php $mySnippets = array(
'Users' => array(
'id1' => 'John',
'id2' => 'Paul',
),
'Phrases' => array(
'Text Foo' => 'foo',
'Text Bar' => 'bar'
)
); ?>
<?php $this->widget(
'application.extensions.ddeditor.DDEditor',
array(
'model'=>$model,
'attribute'=>'content',
'htmlOptions'=>array('rows'=>10, 'cols'=>70),
'previewRequest'=>'post/preview',
'additionalSnippets'=>array('My Snippets'=>$mySnippets),
); ?>
#### Add a Controller Preview Action
In order to receive a rendered preview of the textarea Markdown, add an action method to a controller:
public function actionPreview()
{
$parser=new CMarkdownParser;
echo $parser->safeTransform($_POST['Post'][$_GET['attribute']]);
}
### Resources
* [Demo](http://www.diggin-data.de/ddeditor)
* [Discussion](http://www.yiiframework.com/forum/index.php?/topic/11384-new-extension-markdown-editor)
### Changes
#### March 29, 2010
* **V0.4**
* Added code sample for using _additionalSnippets_ in README
* Added reset of _additional snippets_ dropdown list after selection
#### March 28, 2010
* **V0.3**
* Fixed _Depreciated: split_ warning
* Added _additionalSnippets_ member
* Added _Code Highlighter_ dropdown list
#### August 31, 2010
* **V0.2**
* Fixed setting `$previewReaquest`
* Fixed setting client script id's for using multiple editors in one form
#### August 30, 2010
* **V0.1** Initial release.
|