Awesome
Pagemark
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);