function Markdown($text) { global $g_urls, $g_titles, $g_html_blocks; $g_urls = array(); $g_titles = array(); $g_html_blocks = array(); $text = str_replace(array("\r\n", "\r"), "\n", $text); $text .= "\n\n"; $text = _Detab($text); $text = preg_replace('/^[ \\t]+$/m', '', $text); $text = _HashHTMLBlocks($text); $text = _StripLinkDefinitions($text); $text = _EscapeSpecialChars($text); $text = _RunBlockGamut($text); $text = _UnescapeSpecialChars($text); return $text . "\n"; }
function _RunSpanGamut($text) { # # These are all the transformations that occur *within* block-level # tags like paragraphs, headers, and list items. # global $md_empty_element_suffix; $text = _DoCodeSpans($text); $text = _EscapeSpecialChars($text); # Process anchor and image tags. Images must come first, # because ![foo][f] looks like an anchor. $text = _DoImages($text); $text = _DoAnchors($text); # Make links out of things like `<http://example.com/>` # Must come after _DoAnchors(), because you can use < and > # delimiters in inline links like [this](<url>). $text = _DoAutoLinks($text); # Fix unencoded ampersands and <'s: $text = _EncodeAmpsAndAngles($text); $text = _DoItalicsAndBold($text); # Do hard breaks: $text = preg_replace('/ {2,}\\n/', "<br{$md_empty_element_suffix}\n", $text); return $text; }
function Markdown($text) { # # Main function. The order in which other subs are called here is # essential. Link and image substitutions need to happen before # _EscapeSpecialChars(), so that any *'s or _'s in the <a> # and <img> tags get encoded. # # Clear the global hashes. If we don't clear these, you get conflicts # from other articles when generating a page which contains more than # one article (e.g. an index page that shows the N most recent # articles): global $md_urls, $md_titles, $md_html_blocks; $md_urls = array(); $md_titles = array(); $md_html_blocks = array(); # Standardize line endings: # DOS to Unix and Mac to Unix $text = str_replace(array("\r\n", "\r"), "\n", $text); # Make sure $text ends with a couple of newlines: $text .= "\n\n"; # Convert all tabs to spaces. $text = _Detab($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 /[ \t]*\n+/ . $text = preg_replace('/^[ \\t]+$/m', '', $text); # Turn block-level HTML blocks into hash entries $text = _HashHTMLBlocks($text); # Strip link definitions, store in hashes. $text = _StripLinkDefinitions($text); # _EscapeSpecialChars() must be called very early, to get # backslash escapes processed. $text = _EscapeSpecialChars($text); $text = _RunBlockGamut($text); $text = _UnescapeSpecialChars($text); return $text . "\n"; }