October\Rain\Parse\Markdown

Overview

Markdown helper class.

Calling Markdown::parse($text) returns the HTML corresponding to the Markdown input in $text.

October CMS uses ParsedownExtra as its Markdown parser, but fires markdown.beforeParse and markdown.parse events allowing hooks into the default parsing,

The markdown.beforeParse event passes a MarkdownData instance, containing a public $text variable. Event listeners can modify $text, for example to filter out or protect snippets from being interpreted by ParseDown.

Similarly, markdown.parse is fired after ParseDown has interpreted the (possibly modified) input. This event passes an array [$text, $data], where $text is the original unmodified Markdown input, and $data is the HTML code generated by ParseDown.


Protected Properties

protected ParsedownExtra $parser

parser is the parsedown instance

protected array $emitterSingleEventCollection

emitterSingleEventCollection of events to be fired once only

protected array $emitterEventCollection

emitterEventCollection of all registered events

protected array $emitterEventSorted

emitterEventSorted collection


Public Methods

public bindEvent()

public bindEvent($event, $callback, $priority = 0): void 

bindEvent creates a new event binding

public bindEventOnce()

public bindEventOnce($event, $callback, $priority = 0): void 

bindEventOnce creates a new event binding that fires once only

public fireEvent()

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

fireEvent and call the listeners

public parse()

public parse($text): string 

parse text using Markdown and Markdown-Extra

public parseClean()

public parseClean($text): string 

parseClean enables safe mode where the resulting HTML is cleaned using a sanitizer

public parseIndent()

public parseIndent($text): string 

parseIndent disables code blocks caused by indentation

public parseLine()

public parseLine($text): string 

parseLine parses a single line

public parseSafe()

public parseSafe($text): string 

parseSafe is stricter than parse clean allowing no HTML at all except for basic protocols such as https://, ftps://, mailto:, etc.

public unbindEvent()

public unbindEvent($event = null): void 

unbindEvent destroys an event binding

Protected Methods

protected emitterEventSortEvents()

protected emitterEventSortEvents($eventName, $combined = []): array 

emitterEventSortEvents sorts the listeners for a given event by priority

protected getParser()

protected getParser(): October\Rain\Parse\Parsedown\ParsedownExtra 

getParser returns an instance of the parser

protected parseInternal()

protected parseInternal($text, $method = 'text'): string 

parseInternal is an internal method for parsing