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
= false
Enables the parsing of attributes for block-level and inline content.
public
$autolinking
:
bool
= true
Enables autolinking of URLs and email addresses in Markdown content.
public
$config
:
array
= []
Custom configuration for the CommonMark environment.
public
$footnotes
:
bool
= false
Enables the parsing and generation of footnotes.
public
$frontMatter
:
bool
= false
Enables the parsing of front matter (metadata).
public
$headingPermalinks
:
bool
= false
Enables the generation of permalinks for each heading.
public
$inlineOnly
:
bool
= false
Enables inline-only formatting. This is used for rendering a single line of Markdown.
public
$safeMode
:
bool
= false
Enables safe mode - disables certain HTML tags.
public
$tableOfContents
:
bool
= false
Enables the generation of a table of contents.
public
$tables
:
bool
= true
Enables the generation of tables.
public
$taskLists
:
bool
= false
Enables the parsing and generation of task lists.
protected
$frontMatterData
:
array
|
null
= null
Extracted front matter (metadata) from the Markdown content.
protected
$parserClass
:
string
|
null
= null
The Markdown parser class to use.
protected
$rendererClass
:
string
|
null
= null
The HTML renderer class to use.
inherited
protected
$emitterEventCollection
:
array
= []
Collection of registered events.
inherited
protected
$emitterEventSorted
:
array
= []
Sorted collection of events.
inherited
protected
$emitterSingleEventCollection
:
array
= []
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.
Property | Type | Description |
---|---|---|
$name | string |
string
|
$arguments | array |
array
|
public static __callStatic (string $name, array $arguments) : static
Allows fluent-style enabling and disabling of features from an initial static call.
Property | Type | Description |
---|---|---|
$name | string |
string
|
$arguments | array |
array
|
public final __construct ()
Constructor.
public getFrontMatter () : array
Gets the front matter extracted from the document.
This should be called after the Markdown has been parsed.
public parse (string $markdown) : string
Parse Markdown content and render as HTML.
Property | Type | Description |
---|---|---|
$markdown | string |
string
|
public parseClean (string $markdown) : string
Parse Markdown content and render as HTML, with unsafe tags disabled.
This will prevent tags such as <script>,
Property | Type | Description |
---|---|---|
$markdown | string |
string
|
public parseLine (string $markdown) : string
Parse a single line
Property | Type | Description |
---|---|---|
$markdown | string |
string
|
public parseSafe (string $markdown) : string
Parse Markdown content and render as HTML, with indented code blocks disabled.
Property | Type | Description |
---|---|---|
$markdown | string |
string
|
public setParser (League\CommonMark\Parser\MarkdownParserInterface $parserClass) : void
Sets the Markdown parser to use.
Property | Type | Description |
---|---|---|
$parserClass | League\CommonMark\Parser\MarkdownParserInterface |
League\CommonMark\Parser\MarkdownParserInterface
|
public setRenderer (League\CommonMark\Renderer\DocumentRendererInterface $rendererClass) : void
Sets the HTML renderer to use.
Property | Type | Description |
---|---|---|
$rendererClass | League\CommonMark\Renderer\DocumentRendererInterface |
League\CommonMark\Renderer\DocumentRendererInterface
|
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.
protected extractFrontMatter (string $markdown) : string
Extracts front matter from the Markdown content.
The content, minus the front matter, is returned.
Property | Type | Description |
---|---|---|
$markdown | string |
string
|
protected getDefaultConfig () : array
Returns the default configuration for the Markdown environment.
protected getParser (League\CommonMark\Environment\Environment $environment) : League\CommonMark\Parser\MarkdownParserInterface
Gets an instance of the Markdown parser within a given environment.
Property | Type | Description |
---|---|---|
$environment | League\CommonMark\Environment\Environment |
League\CommonMark\Environment\Environment
|
protected getRenderer (League\CommonMark\Environment\Environment $environment) : League\CommonMark\Renderer\DocumentRendererInterface
Gets an instance of the HTML renderer within a given environment.
Property | Type | Description |
---|---|---|
$environment | League\CommonMark\Environment\Environment |
League\CommonMark\Environment\Environment
|
protected parseInternal (League\CommonMark\Environment\Environment $environment, string $markdown) : string
Internal method for parsing
Property | Type | Description |
---|---|---|
$environment | League\CommonMark\Environment\Environment |
League\CommonMark\Environment\Environment
|
$markdown | string |
string
|
inherited
public
bindEvent (string | Closure | QueuedClosure $event, mixed $callback = null
, integer $priority)
: self
Create a new event binding.
Property | Type | Description |
---|---|---|
$event | string | Closure | QueuedClosure |
string | Closure | QueuedClosure
|
$callback | mixed |
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 |
integer
|
inherited
public
bindEventOnce (string | Closure | QueuedClosure $event, QueuedClosure | Closure | null $callback = null
)
: self
Create a new event binding that fires once only
Property | Type | Description |
---|---|---|
$event | string | Closure | QueuedClosure |
string | Closure | QueuedClosure
|
$callback | QueuedClosure | Closure | null |
QueuedClosure | Closure | null
When a Closure or QueuedClosure is provided as the first parameter this parameter can be omitted |
inherited
public
fireEvent (string $event, array $params = []
, boolean $halt = false
)
: array | mixed | null
Fire an event and call the listeners.
Property | Type | Description |
---|---|---|
$event | string |
string
Event name |
$params | array |
array
Event parameters |
$halt | boolean |
boolean
Halt after first non-null result |
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
Destroys an event binding.
Property | Type | Description |
---|---|---|
$event | string | array | object |
string | array | object
Event to destroy |
inherited protected emitterEventSortEvents (string $eventName) : void
Sort the listeners for a given event by priority.
Property | Type | Description |
---|---|---|
$eventName | string |
string
|
inherited
protected
parseEventAndPayload (mixed $event, mixed $payload = null
)
: array
Parse the given event and payload and prepare them for dispatching.
Property | Type | Description |
---|---|---|
$event | mixed |
mixed
|
$payload | mixed |
mixed
|