ddeditor Markdown Editor with Preview

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
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.
3 0
6 followers
1 587 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: User Interface
Developed by: jwerner
Created on: Aug 30, 2010
Last updated: 13 years ago

Downloads

show all

Related Extensions