function _RunSpanGamut($text) { global $g_empty_element_suffix; $text = _DoCodeSpans($text); $text = _EncodeAmpsAndAngles($text); $text = _DoImages($text); $text = _DoAnchors($text); $text = _DoItalicsAndBold($text); # Do hard breaks: $text = preg_replace('/ {2,}\\n/', "<br{$g_empty_element_suffix}\n", $text); return $text; }
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); # Fix unencoded ampersands and <'s: $text = _EncodeAmpsAndAngles($text); # Process anchor and image tags. Images must come first, # because ![foo][f] looks like an anchor. $text = _DoImages($text); $text = _DoAnchors($text); $text = _DoItalicsAndBold($text); # Do hard breaks: $text = preg_replace('/ {2,}\\n/', "<br{$md_empty_element_suffix}\n", $text); return $text; }
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 _DoTable_callback($matches) { $head = $matches[1]; $underline = $matches[2]; $content = $matches[3]; # Remove any tailing pipes for each line. $head = preg_replace('/[|] *$/m', '', $head); $underline = preg_replace('/[|] *$/m', '', $underline); $content = preg_replace('/[|] *$/m', '', $content); # Reading alignement from header underline. $separators = preg_split('/ *[|] */', $underline); foreach ($separators as $n => $s) { if (preg_match('/^ *-+: *$/', $s)) { $attr[$n] = ' align="right"'; } else { if (preg_match('/^ *:-+: *$/', $s)) { $attr[$n] = ' align="center"'; } else { if (preg_match('/^ *:-+ *$/', $s)) { $attr[$n] = ' align="left"'; } else { $attr[$n] = ''; } } } } # Creating code spans before splitting the row is an easy way to # handle a code span containg pipes. $head = _DoCodeSpans($head); $headers = preg_split('/ *[|] */', $head); $col_count = count($headers); # Write column headers. $text = "<table>\n"; $text .= "<thead>\n"; $text .= "<tr>\n"; foreach ($headers as $n => $header) { $text .= " <th{$attr[$n]}>" . _RunSpanGamut(trim($header)) . "</th>\n"; } $text .= "</tr>\n"; $text .= "</thead>\n"; # Split content by row. $rows = explode("\n", trim($content, "\n")); $text .= "<tbody>\n"; foreach ($rows as $row) { # Creating code spans before splitting the row is an easy way to # handle a code span containg pipes. $row = _DoCodeSpans($row); # Split row by cell. $row_cells = preg_split('/ *[|] */', $row, $col_count); $row_cells = array_pad($row_cells, $col_count, ''); $text .= "<tr>\n"; foreach ($row_cells as $n => $cell) { $text .= " <td{$attr[$n]}>" . _RunSpanGamut(trim($cell)) . "</td>\n"; } $text .= "</tr>\n"; } $text .= "</tbody>\n"; $text .= "</table>"; return _HashBlock($text) . "\n"; }