You are here

public function Markdown::transform in Express 8

* Main function. Performs some preprocessing on the input text and pass * it through the document gamut. * * @api * *

Parameters

string $text: * @return string

Overrides MarkdownInterface::transform

File

vendor/michelf/php-markdown/Michelf/Markdown.php, line 222

Class

Markdown
Markdown Parser Class

Namespace

Michelf

Code

public function transform($text) {
  $this
    ->setup();

  # Remove UTF-8 BOM and marker character in input, if present.
  $text = preg_replace('{^\\xEF\\xBB\\xBF|\\x1A}', '', $text);

  # Standardize line endings:

  #   DOS to Unix and Mac to Unix
  $text = preg_replace('{\\r\\n?}', "\n", $text);

  # Make sure $text ends with a couple of newlines:
  $text .= "\n\n";

  # Convert all tabs to spaces.
  $text = $this
    ->detab($text);

  # Turn block-level HTML blocks into hash entries
  $text = $this
    ->hashHTMLBlocks($text);

  # Strip any lines consisting only of spaces and tabs.

  # This makes subsequent regexen easier to write, because we can

  # match consecutive blank lines with /\n+/ instead of something

  # contorted like /[ ]*\n+/ .
  $text = preg_replace('/^[ ]+$/m', '', $text);

  # Run document gamut methods.
  foreach ($this->document_gamut as $method => $priority) {
    $text = $this
      ->{$method}($text);
  }
  $this
    ->teardown();
  return $text . "\n";
}