Yii 2.0: yii2-markdown

Advanced Markdown editing and conversion utilities for Yii Framework 2.0
30 followers

This module provides Markdown Editing and Conversion utilities for Yii Framework 2.0. It implements markdown conversion using PHP Markdown Extra and PHP Smarty Pants Typographer. In addition, you can customize the flavor of Markdown, by including additional custom conversion patterns. The module also includes an enhanced customized Markdown Editor Widget for markdown editing and preview at runtime. This widget is styled using Twitter Bootstrap 3.0. View a complete demo.

Markdown

VIEW DEMO
This is a markdown converter class that extends Yii's Markdown Helper with advanced functionality. The converter uses PHP Markdown Extra and PHP SmartyPantsTypographer for processing Markdown conversion to HTML. It also supports configurable custom conversion processing of patterns for styling your own flavour of Markdown to some extent. View examples and details or view a complete demo.

MarkdownEditor

VIEW DEMO
This is an advanced markdown input widget with configurable options. It is styled using Twitter Bootstrap 3.0. Key features available with this widget are:

  1. Configurable toolbar and buttons for formatting content
  2. Live preview of Markdown formatted text as HTML
  3. Maximize editor for full screen editing
  4. Implements PHP Markdown Extra and PHP SmartyPantsTypographer functionality as provided by the Markdown.
  5. Uses Twitter Bootstrap 3.0 styling wherever possible
  6. Allows saving/exporting of the text-editor contents as Text or HTML
  7. Configurable header, footer, and input options.
  8. Supports localization and customization of messages and content.

View examples and details or view a complete demo.

Requirements

  • Yii 2.0 (dev-master)
  • PHP 5.4
  • Twitter Bootstrap 3.0
  • PHP SmartyPantsTypographer

Note: This extension mandatorily requires Yii Framework 2. The framework is under active development and the first stable release of Yii 2 is expected in early 2014.

Installation

The preferred way to install this extension is through composer.

Either run

$ php composer.phar require kartik-v/yii2-markdown "dev-master"

or add

"kartik-v/yii2-markdown": "dev-master"

to the require section of your composer.json file.

Usage

Setup Module

Add markdown to your modules section of your Yii configuration file

'modules' = [
    /* other modules */
    'markdown' => [
        'class' => 'kartik\markdown\Module',
    ]
];

You can setup additional configuration options for the markdown module:

'modules' = [
    /* other modules */
    'markdown' => [
        // the module class
        'class' => 'kartik\markdown\Module',
 
        // the controller action route used for markdown editor preview
        'previewAction' => '/markdown/parse/preview',
 
        // the list of custom conversion patterns for post processing
        'customConversion' => [
            '<table>' => '<table class="table table-bordered table-striped">'
        ],
 
        // whether to use PHP SmartyPantsTypographer to process Markdown output
        'smartyPants' => true
 
    ]
];

Markdown

use kartik\markdown\Markdown;
 
// default call
echo Markdown::convert($content);
 
// with custom post processing
echo Markdown::convert($content, ['custom' => [
    '<h1>' => '<h1 class="custom-h1>',
    '<h2>' => '<h1 class="custom-h2>',
]]);

MarkdownEditor

// add this in your view
use kartik\markdown\MarkdownEditor;
 
// usage with model
echo MarkdownEditor::widget([
    'model' => $model, 
    'attribute' => 'markdown',
]);
 
// usage without model
echo MarkdownEditor::widget([
    'name' => 'markdown', 
    'value' => $value,
]);

Report

License

yii2-markdown is released under the BSD 3-Clause License. See the bundled LICENSE.md for details.

Resources

Total 5 comments

#16389 report it
Kartik V at 2014/02/17 01:00pm
Message Translations

You may add translated messages for your language in this location through a Github PR.

#16388 report it
davey` at 2014/02/17 12:38pm
That was fast!

Good job, thank you!

Sure I will take a look at it. I'll need to localize it for my project anyway :)

#16387 report it
Kartik V at 2014/02/17 12:21pm
Upgraded SmartyPants to SmartyPants Typographer

Upgraded the extension to use PHP SmartyPantsTypographer instead of PHP SmartyPants. Check the details and demo.

@davey Hope this help your cause. You may want to contribute to French message translation at the project page to help you and other folks in French language projects.

#16386 report it
davey` at 2014/02/17 11:50am
Great extension!

I've been looking around and all your extensions are very useful and pretty solid.

I'll be using them in my project :)

One improvement suggestion: could you please make it possible to use SmartyPantsTypographer instead of SmartyPants?

I'm really interested in the additional transformations it provides (I'm French and the French guillemets would be a nice touch).

Thanks!

#16035 report it
Kartik V at 2014/01/13 12:18pm
Multiple fixes and enhancements

Several issues/enhancements addressed in the extension now. Visit the project issues page to check details.

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet