站长资讯网
最全最丰富的资讯网站

php如何实现markdown转html

php实现markdown转html的方法:用markdown编辑api的方式,代码为【$fileContent = file_get_contents(storage_path('doc/admin_api.md'))】。

php如何实现markdown转html

【相关学习推荐:php编程(视频)】

php实现markdown转html的方法:

使用插件实现markdown转为html

功能很简单,就直接上代码啦。

<?php namespace AppHttpControllersAdmin; use IlluminateHttpRequest; use AppHttpControllersController; use Parsedown; class ApiDocController extends Controller {     public function __construct(){         $this->markdownParser = new Parsedown();     }     public function showDoc(Request $request){         $fileContent = file_get_contents(storage_path('doc/admin_api.md'));         $htmlContent = $this->convertMarkdownToHtml($fileContent);         $content = $this->convertMarkdownToHtml($htmlContent);         return view('apidoc_admin')->with('content',$content);     }     public function convertMarkdownToHtml($markdown)     {         $convertedHmtl = $this->markdownParser->setBreaksEnabled(true)->text($markdown);         return $convertedHmtl;     } }

本文推荐的就是用markdown编辑api的方式,md就是markdown文件的后缀,我现在把这个文件放在storage/doc/admin_api.md处。

为了测试,我暂时在文件里粘贴了一个markdown格式的api:

**简要描述:**  - 用户登录接口 **请求URL:**  - ` http://xx.com/api/user/login `    **请求方式:** - POST  **参数:**  |参数名|必选|类型|说明| |:----    |:---|:----- |-----   | |username |是  |string |用户名   | |password |是  |string | 密码    |  **返回示例** ```    {     "error_code": 0,     "data": {       "uid": "1",       "username": "zhai coder",       "name": "璇哈",       "groupid": 2 ,       "reg_time": "2019-08-01",       "last_login_time": "0",     }   } ```  **返回参数说明**  |参数名|类型|说明| |:-----  |:-----|-----                           | |groupid |int   |用户组id,1:超级管理员;2:普通用户  |  **备注**  - 

赞(0)
分享到: 更多 (0)