fungku/postmark

此包已被 弃用 并且不再维护。作者建议使用 ryanwinchester/pagemark 包代替。

解析博客或维基的Markdown

v0.6.0 2016-04-29 17:52 UTC

This package is auto-updated.

Last update: 2022-02-01 12:46:54 UTC


README

Version Total Downloads License Scrutinizer Code Quality Build Status

解析博客和维基的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>'
];

说明

  1. $title - 从文件或目录名称中获取的文章或分类标题。
  2. $breadcrumbs 是一个包含面包屑的数组。
  3. $index 在您导航到目录时可用,否则为空数组
    • $index['subcategories'] 是当前目录中的子目录数组
    • $index['files'] 是当前目录中的文件数组
  4. $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);