ryanwinchester / pagemark
Parse markdown for a blog or wiki
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: 2024-11-28 23:06:18 UTC
README
Parse markdown pages for blogs and wikis
There are multiple ways to get the content.
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);
Example return value
$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>' ];
Explanation:
$title
- The title of the post or category taken from the file or directory name.$breadcrumbs
is an array of breadcrumbs.$index
is available if you have navigated to a directory, or an empty array otherwise$index['subcategories']
is an array of subdirectories in your current directory$index['files']
is an array of files in your current directory
$post
is a string of your parsed markdown content
Using a different parser.
By default the markdown parser used is erusev/parsedown. To use a different one,
you need to make your own parser that implements the Parseable
interface or create an adapter for a different library
that implements 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);