/**
  *
  * Main function. Performs some preprocessing on the input text
  * and pass it through the document gamut.
  *
  */
 public static function transform($text)
 {
     /**
      * From previous constructor
      */
     self::_init_detab();
     self::prepare_italics_and_bold();
     self::$nested_brackets_re = str_repeat('(?>[^\\[\\]]+|\\[', self::$nested_brackets_depth) . str_repeat('\\])*', self::$nested_brackets_depth);
     self::$nested_url_parenthesis_re = str_repeat('(?>[^()\\s]+|\\(', self::$nested_url_parenthesis_depth) . str_repeat('(?>\\)))*', self::$nested_url_parenthesis_depth);
     self::$escape_chars_re = '[' . preg_quote(self::$escape_chars) . ']';
     // Sort document, block, and span gamut in ascendent priority order.
     asort(self::$document_gamut);
     asort(self::$block_gamut);
     asort(self::$span_gamut);
     /**
      * End of constructor stuff
      */
     self::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 = self::detab($text);
     // Turn block-level HTML blocks into hash entries
     $text = self::hash_HTML_blocks($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 (self::$document_gamut as $method => $priority) {
         $text = self::$method($text);
     }
     self::teardown();
     return $text . "\n";
 }