fungku / postmark
v0.6.0
2016-04-29 17:52 UTC
Requires
- php: >=5.4.0
- erusev/parsedown: ~1.5
- illuminate/filesystem: ~5.0
Requires (Dev)
- phpspec/phpspec: ~2.1
This package is auto-updated.
Last update: 2022-02-01 12:46:54 UTC
README
解析博客和维基的Markdown页面
有多种方式获取内容。
use Pagemark\Pagemark; $basePath = '/my/path/to/wiki'; $post = 'Category/Subcategory/My-Post'; $content = Pagemark::parse($basePath, $post);
use Pagemark\Pagemark; $pagemark = Pagemark::create(); $basePath = '/my/path/to/wiki'; $post = 'Category/Subcategory/My-Post'; $content = $pagemark->getContent($basePath, $post);
use Pagemark\Pagemark; use Pagemark\Parser; use Illuminate\Filesystem\Filesystem; use Parsedown; $pagemark = new Pagemark(new Filesystem, new Parser(new Parsedown)); $basePath = '/my/path/to/wiki'; $post = 'Category/Subcategory/My-Post'; $content = $pagemark->getContent($basePath, $post);
示例返回值
$content = [ 'title' => 'File', 'breadcrumbs' => [ [ 'href' => '/Category', 'name' => 'Category' ], [ 'href' => '/Category/Subcategory', 'name' => 'Subcategory' ], [ 'href' => '/Category/Subcategory/My-Post', 'name' => 'My Post' ], ], 'index' => ['subcategories' => [], 'files' => []], 'post' => '<p>Some text from My-Post.md</p>' ];
说明
$title
- 从文件或目录名称中获取的文章或分类标题。$breadcrumbs
是一个包含面包屑的数组。$index
在您导航到目录时可用,否则为空数组$index['subcategories']
是当前目录中的子目录数组$index['files']
是当前目录中的文件数组
$post
是您解析的Markdown内容的字符串
使用不同的解析器。
默认情况下使用的Markdown解析器是 erusev/parsedown。要使用不同的解析器,您需要创建自己的实现 Parseable
接口的解析器或为实现 Parseable
的不同库创建适配器。
use Pagemark\Pagemark; $myCustomParser = new CustomParser; $pagemark = Pagemark::create($myCustomParser); $basePath = '/my/path/to/wiki'; $post = 'Category/Subcategory/My-Post'; $content = $pagemark->getContent($basePath, $post);
use Pagemark\Pagemark; use Pagemark\Parser; use Illuminate\Filesystem\Filesystem; $myCustomParser = new CustomParser; $pagemark = new Pagemark(new Filesystem, $myCustomParser); $basePath = '/my/path/to/wiki'; $post = 'Category/Subcategory/My-Post'; $content = $pagemark->getContent($basePath, $post);