dev-master
9999999-devMarkdown Parser
MIT
The Requires
The Development Requires
php markdown
Wallogit.com
2017 © Pedro Peláez
Markdown Parser
A modular parser for CommonMark, GitHub-Flavoured-Markdown, and beyond. Lovingly crafted in PHP 7.1., (*1)
One of the main objectives for this parser is creating a system where CommonMark, GitHub-Flavoured-Markdown, and [insert your own dialects here] can co-exist and specific inline/block elements from each can be used in a modular fashion., (*2)
(there will be a YAML file config for authors to use to piece this selection together eventually)., (*3)
Another objective is usability, and with that comes a variety of things, including but not limited to: * Accuracy of the built in dialects(/flavours) to their specifications * A variety of output formats, creating abstract implementations of common structures (so that slight modifications e.g. particular marker used, how many are used is trivial to adjust) * Creating a general purpose parsing strategy such that implementations of specific inlines/blocks do not have to be aware of each other, or of how they should cope with various types of intersections. (e.g. inline elements that can be extended to avoid intersection will be without the inline implementation having to be aware that this is possible)., (*4)
Emphasis and strong emphasis are by far the most complex inline structures. One of the aims of this parser is to have lots of reusable code., (*5)
Here we have an abstraction of emphasis (like a CommonMark emphasis, except number of delimiters in a delimiter run is arbitrary – like inline code)., (*6)
This is everything we need to define a new type of emphasis, strikethrough., (*7)
<?php
declare(strict_types=1);
namespace Parsemd\Parsemd\Parsers\Aidantwoods\Inlines;
use Parsemd\Parsemd\Parsers\Inline;
use Parsemd\Parsemd\Parsers\Parsemd\Abstractions\Inlines\Emphasis;
class StrikeThrough extends Emphasis implements Inline
{
protected const TAG = 'del';
protected const MARKERS = [
'~'
];
}
Infact, the CommonMark emphasis implementation too extends this abstract
idea. Though some adjustments have to be made to separate the * delimiter from
the ** delimiter, and so-forth for _., (*8)
That implementation is only slightly longer though. Here it is., (*9)
<?php
declare(strict_types=1);
namespace Parsemd\Parsemd\Parsers\CommonMark\Inlines;
use Parsemd\Parsemd\Parsers\Inline;
use Parsemd\Parsemd\Parsers\Parsemd\Abstractions\Inlines\Emphasis;
class ShortEmph extends Emphasis implements Inline
{
protected const TAG = 'em';
protected const MARKERS = [
'*', '_'
];
protected const INTRAWORD_MARKER_BLACKLIST = [
'_'
];
protected const MAX_RUN = 1;
protected const MIN_RUN = 1;
}
Markdown Parser
MIT
php markdown