jormin/md-convert

Markdown 转 Html 或 PDF

v1.0.0 2018-09-05 07:35 UTC

This package is auto-updated.

Last update: 2024-04-06 09:21:22 UTC


README

Markdown 转 Html 或 PDF

安装

$ composer require jormin/md-convert -vvv

通用响应

参数 类型 是否必须 描述
success bool false:操作失败 true:操作成功
message string 结果说明
data array 返回数据

使用

生成转换对象

$mdConvert = \Jormin\MDConvert\MDConvert::load();

转换Html

转换结果为 zip 压缩包,包含 html 文件和 css 文件

/**
 * 转换Html
 *
 * @param string $mdFile Markdown源文件绝对路径,需要可读
 * @param string $savePath 转换后文件存储目录,需要可读可写,为空默认使用源文件目录
 * @param array $saveName 转换后文件名称,为空默认使用源文件名称
 * @return array
 */
$mdConvert->toHtml($mdFile, [$savePath=null, $saveName=null]);

转换PDF

/**
 * 转换PDF
 *
 * @param string $mdFile Markdown源文件绝对路径,需要可读
 * @param string $savePath 转换后文件存储目录,需要可读可写,为空默认使用源文件目录
 * @param array $saveName 转换后文件名称,为空默认使用源文件名称
 * @return array
 */
$mdConvert->toPDF($mdFile, [$savePath=null, $saveName=null]);

参考扩展

  1. erusev/parsedown

  2. mpdf/mpdf

License

The MIT License (MIT). Please see License File for more information.