定制 maurymmarques/markdown-plugin 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

maurymmarques/markdown-plugin

Composer 安装命令:

composer require maurymmarques/markdown-plugin

包简介

A CakePHP plugin that facilitates the use of PHP Markdown with CakePHP

README 文档

README

This plugin facilitates the use of PHP Markdown with CakePHP

PHP Markdown is a port to PHP of the Markdown program written by John Gruber.

“Markdown” is two things: a plain text markup syntax, and a software tool that converts the plain text markup to HTML for publishing on the web.

More info: http://michelf.com/projects/php-markdown

For this plugin, the application Markdown is inside Vendor

Version

Written for CakePHP 2.x

Copyright

Copyright (c) 2011 Maury M. Marques

Installation

You can install this plugin using Composer, GIT Submodule, GIT Clone or Manually

[Using Composer]

Add the plugin to your project's composer.json - something like this:

{
  "require": {
    "maurymmarques/markdown-plugin": "dev-master"
  },
  "extra": {
    "installer-paths": {
      "app/Plugin/Markdown": ["maurymmarques/markdown-plugin"]
    }
  }
}

Then just run composer install

Because this plugin has the type cakephp-plugin set in it's own composer.json, composer knows to install it inside your /Plugin directory, rather than in the usual vendors file.

[GIT Submodule]

In your app directory (app/Plugin) type:

git submodule add git://github.com/maurymmarques/markdown-cakephp.git Plugin/Markdown
git submodule init
git submodule update

[GIT Clone]

In your plugin directory (app/Plugin or plugins) type:

git clone https://github.com/maurymmarques/markdown-cakephp.git Markdown

[Manual]

  • Download the Markdown archive.
  • Unzip that download.
  • Rename the resulting folder to Markdown
  • Then copy this folder into app/Plugin/ or plugins

Configuration

Bootstrap the plugin in app/Config/bootstrap.php:

CakePlugin::load(array('Markdown' => array('bootstrap' => true)));

Usage

Enable the helper using the plugin syntax

If desired, set the component to assist with the return of data from the markdown.

// in app/Controller/BakeriesController.php
class BakeriesController extends AppController {

		public $helpers = array('Markdown.Markdown');

		public function index() {
			$this->set('textInMarkdownFormat', $yourTextInMarkdownFormat);
		}
}

Or, if the markdown content is in a file...

// in app/Controller/BakeriesController.php
class BakeriesController extends AppController {

		public $helpers = array('Markdown.Markdown');
		public $components = array('Markdown.Markdown');

		public function index() {
			$this->set('textInMarkdownFormat', $this->Markdown->getFile($pathToMarkdownFile));
		}
}

In the view you can use something like:

// in app/View/Bakeries/index.ctp
echo $this->Markdown->transform($textInMarkdownFormat);

In the model you can use something like:

// in app/Model/Bakery.php
class BakeryModel extends AppModel {
	
	public $actsAs = array('Markdown.Markdown');

	public function beforeSave($options = array()) {
		$this->data[$this->alias]['text_html'] = $this->transform( $this->data[$this->alias]['text_md'] );
		return true;
	}
}

统计信息

  • 总下载量: 16.78k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 24
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 23
  • Watchers: 4
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-02-08