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 October\Rain\Parse\Parsedown\Parsedown $parser

parser is the parsedown instance

protected array $emitterSingleEventCollection

Collection of registered events to be fired once only.

protected array $emitterEventCollection

Collection of registered events.

protected array $emitterEventSorted

Sorted collection of events.

Public methods

public self bindEvent($event, $callback, $priority=0)

Create a new event binding.

  • $event
  • $callback
  • $priority

public self bindEventOnce($event, $callback)

Create a new event binding that fires once only

  • $event
  • $callback

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

Fire an event and call the listeners.

  • string $event - Event name
  • array $params - Event parameters
  • boolean $halt - Halt after first non-null result

public void parse($text)

parse text using Markdown and Markdown-Extra

  • $text

public void parseClean($text)

parseClean enables safe mode where HTML is escaped

  • $text

public void parseLine($text)

parseLine parses a single line

  • $text

public void parseSafe($text)

parseSafe disables code blocks caused by indentation

  • $text

public self unbindEvent(string $event=NULL)

Destroys an event binding.

  • string $event - Event to destroy

Protected methods

protected array emitterEventSortEvents(string $eventName)

Sort the listeners for a given event by priority.

  • string $eventName

protected void getParser()

getParser returns an instance of the parser

protected void parseInternal($text, $method='text')

parseInternal is an internal method for parsing

  • $text
  • $method