# 文件結構
* 插件文件結構如下
~~~
plugins\Markdown
---------config.php
---------Markdown.php
|controller
----|Markdown.php
|libs
|parsedown|Parsedown.php
~~~
## 文件詳細代碼 如下
* config.php 內容為空
* plugins\Markdown\Markdown.php
~~~
<?php
// +----------------------------------------------------------------------
// | 介紹信息 [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) gyhong【巖路】 All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: gyhong <gyh9711@163.com>
// | datetime: 2017-10-26 11:15
// | filename: Markdown.php
// +----------------------------------------------------------------------
namespace plugins\Markdown;
use app\common\controller\Plugin;
class Markdown extends Plugin
{
public $info = [
// 插件名[必填]
'name' => 'Markdown',
// 插件標題[必填]
'title' => 'Markdown',
// 插件唯一標識[必填],格式:插件名.開發者標識.plugin
'identifier' => 'Markdown.gyh9711.plugin',
// 插件圖標[選填]
'icon' => 'fa fa-fw fa-envelope-o',
// 插件描述[選填]
'description' => 'Markdown插件,使用Parsedown庫',
// 插件作者[必填]
'author' => 'gyh9711',
// 作者主頁[選填]
'author_url' => '',
// 插件版本[必填],格式采用三段式:主版本號.次版本號.修訂版本號
'version' => '1.0.0',
// 是否有后臺管理功能[選填]
'admin' => '0',
];
/**
* 安裝方法
* @return bool
*/
public function install(){
return true;
}
/**
* 卸載方法必
* @return bool
*/
public function uninstall(){
return true;
}
}
~~~
* plugins\Markdown\controller\Markdown.php
~~~
<?php
namespace plugins\Markdown\controller;
use app\common\controller\Common;
// use think\Exception;
// use think\Validate;
//加載markdown解釋庫
include config('plugin_path').'Markdown'.DS.'libs'.DS.'parsedown'.DS.'Parsedown.php';
use Parsedown;
class Markdown extends Common
{
protected static $config; //配置
protected function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
}
/**
* 解釋markdown文件成html
* @param string $title 文件
* @return string 返回html文件內容
*/
public static function output($fileName = null)
{
$fileName = $fileName==null?config('plugin_path').'Markdown'.DS.'libs'.DS.'parsedown'.DS.'README.md':$fileName;
if (file_exists($fileName)){
$Parsedown = new Parsedown();
$output = $Parsedown->text(file_get_contents($fileName));
} else {
$output = '';
}
return $output;
}
}
~~~
# 應用
* 應用控制器中調用插件解決 c:\盤中的 c:\test.md文件
~~~
.......
public function test($model=null){
$res = plugin_action('Markdown','Markdown','output',['c:\\test.md']); //markdown插件應用測試
return $res;
}
~~~
>[info] md文件最好用絕對路徑