Markdown

Markdown parser.

 class Winter\Storm\Parse\Markdown

This parser allows the parsing and interpretation of Markdown content into raw HTML, as well as extracting metadata from the Markdown content as necessary.

This utility has been significantly rewritten to take advantage of the CommonMark library by The PHP League, and more closely adheres to the CommonMark specification, with GitHub-flavored Markdown support.

Traits

Trait Description
Emitter

Adds event related features to any class.

Properties

public $attributes : bool

Enables the parsing of attributes for block-level and inline content.

public $autolinking : bool

Enables autolinking of URLs and email addresses in Markdown content.

public $config : array

Custom configuration for the CommonMark environment.

public $footnotes : bool

Enables the parsing and generation of footnotes.

public $frontMatter : bool

Enables the parsing of front matter (metadata).

public $headingPermalinks : bool

Enables the generation of permalinks for each heading.

public $inlineOnly : bool

Enables inline-only formatting. This is used for rendering a single line of Markdown.

public $safeMode : bool

Enables safe mode - disables certain HTML tags.

public $tableOfContents : bool

Enables the generation of a table of contents.

public $tables : bool

Enables the generation of tables.

public $taskLists : bool

Enables the parsing and generation of task lists.

protected $frontMatterData : array | null

Extracted front matter (metadata) from the Markdown content.

protected $parserClass : string | null

The Markdown parser class to use.

protected $rendererClass : string | null

The HTML renderer class to use.

inherited protected $emitterEventCollection : array

Inherited from Emitter

Collection of registered events.

inherited protected $emitterEventSorted : array

Inherited from Emitter

Sorted collection of events.

inherited protected $emitterSingleEventCollection : array

Inherited from Emitter

Collection of registered events to be fired once only.

Methods

public __call (string $name, array $arguments) : static

Allows fluent-style enabling and disabling of features.

Parameters
Property Description
$name
string
$arguments
array
Returns
static

public static __callStatic (string $name, array $arguments) : static

Allows fluent-style enabling and disabling of features from an initial static call.

Parameters
Property Description
$name
string
$arguments
array
Returns
static

public final __construct ()

Constructor.

Returns
mixed

public getFrontMatter () : array

Gets the front matter extracted from the document.

This should be called after the Markdown has been parsed.

Returns
array

public parse (string $markdown) : string

Parse Markdown content and render as HTML.

Parameters
Property Description
$markdown
string
Returns
string

public parseClean (string $markdown) : string

Parse Markdown content and render as HTML, with unsafe tags disabled.

This will prevent tags such as <script>, , <iframe> from being rendered in the HTML output.

Parameters
Property Description
$markdown
string
Returns
string

public parseLine (string $markdown) : string

Parse a single line

Parameters
Property Description
$markdown
string
Returns
string

public parseSafe (string $markdown) : string

Parse Markdown content and render as HTML, with indented code blocks disabled.

Parameters
Property Description
$markdown
string
Returns
string

public setParser (League\CommonMark\Parser\MarkdownParserInterface $parserClass) : void

Sets the Markdown parser to use.

Parameters
Property Description
$parserClass
League\CommonMark\Parser\MarkdownParserInterface
Returns
void

public setRenderer (League\CommonMark\Renderer\DocumentRendererInterface $rendererClass) : void

Sets the HTML renderer to use.

Parameters
Property Description
$rendererClass
League\CommonMark\Renderer\DocumentRendererInterface
Returns
void

protected createEnvironment () : League\CommonMark\Environment\Environment

Creates a CommonMark environment for each parse.

The environment will also be extended with the necessary extensions that are needed to support the features enabled for this instance of the parser.

Returns
League\CommonMark\Environment\Environment

protected extractFrontMatter (string $markdown) : string

Extracts front matter from the Markdown content.

The content, minus the front matter, is returned.

Parameters
Property Description
$markdown
string
Returns
string

protected getDefaultConfig () : array

Returns the default configuration for the Markdown environment.

Returns
array

protected getParser (League\CommonMark\Environment\Environment $environment) : League\CommonMark\Parser\MarkdownParserInterface

Gets an instance of the Markdown parser within a given environment.

Parameters
Property Description
$environment
League\CommonMark\Environment\Environment
Returns
League\CommonMark\Parser\MarkdownParserInterface

protected getRenderer (League\CommonMark\Environment\Environment $environment) : League\CommonMark\Renderer\DocumentRendererInterface

Gets an instance of the HTML renderer within a given environment.

Parameters
Property Description
$environment
League\CommonMark\Environment\Environment
Returns
League\CommonMark\Renderer\DocumentRendererInterface

protected parseInternal (League\CommonMark\Environment\Environment $environment, string $markdown) : string

Internal method for parsing

Parameters
Property Description
$environment
League\CommonMark\Environment\Environment
$markdown
string
Returns
string

inherited public bindEvent (string | Closure | QueuedClosure $event, mixed $callback = null, integer $priority) : self

Inherited from Emitter

Create a new event binding.

Parameters
Property Description
$event
string | Closure | QueuedClosure
$callback
mixed

when the third parameter is omitted and a Closure or QueuedClosure is provided this parameter is used as an integer this is used as priority variable

$priority
integer
Returns
self

inherited public bindEventOnce (string | Closure | QueuedClosure $event, QueuedClosure | Closure | null $callback = null) : self

Inherited from Emitter

Create a new event binding that fires once only

Parameters
Property Description
$event
string | Closure | QueuedClosure
$callback
QueuedClosure | Closure | null

When a Closure or QueuedClosure is provided as the first parameter this parameter can be omitted

Returns
self

inherited public fireEvent (string $event, array $params = [], boolean $halt = false) : array | mixed | null

Inherited from Emitter

Fire an event and call the listeners.

Parameters
Property Description
$event
string

Event name

$params
array

Event parameters

$halt
boolean

Halt after first non-null result

Returns
array | mixed | null

If halted, the first non-null result. If not halted, an array of event results. Returns null if no listeners returned a result.

inherited public unbindEvent (string | array | object $event = null) : self

Inherited from Emitter

Destroys an event binding.

Parameters
Property Description
$event
string | array | object

Event to destroy

Returns
self

inherited protected emitterEventSortEvents (string $eventName) : void

Inherited from Emitter

Sort the listeners for a given event by priority.

Parameters
Property Description
$eventName
string
Returns
void

inherited protected parseEventAndPayload (mixed $event, mixed $payload = null) : array

Inherited from Emitter

Parse the given event and payload and prepare them for dispatching.

Parameters
Property Description
$event
mixed
$payload
mixed
Returns
array
Copyright © 2024 Winter CMS