You are here

function Markdown_Parser::transform in Markdown 5

Same name and namespace in other branches
  1. 6 markdown.php \Markdown_Parser::transform()

File

./markdown.php, line 284

Class

Markdown_Parser

Code

function transform($text) {

  #

  # Main function. Performs some preprocessing on the input text

  # and pass it through the document gamut.

  #
  $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";
}