You are here

function Markdown_Parser::parseSpan in Markdown 6

Same name and namespace in other branches
  1. 5 markdown.php \Markdown_Parser::parseSpan()
1 call to Markdown_Parser::parseSpan()
MarkdownExtra_Parser::_doTable_callback in ./markdown.php

File

./markdown.php, line 1538

Class

Markdown_Parser

Code

function parseSpan($str) {

  #

  # Take the string $str and parse it into tokens, hashing embeded HTML,

  # escaped characters and handling code spans.

  #
  $output = '';
  $span_re = '{
				(
					\\\\' . $this->escape_chars_re . '
				|
					(?<![`\\\\])
					`+						# code span marker
			' . ($this->no_markup ? '' : '
				|
					<!--    .*?     -->		# comment
				|
					<\\?.*?\\?> | <%.*?%>		# processing instruction
				|
					<[!$]?[-a-zA-Z0-9:_]+	# regular tags
					(?>
						\\s
						(?>[^"\'>]+|"[^"]*"|\'[^\']*\')*
					)?
					>
				|
					<[-a-zA-Z0-9:_]+\\s*/> # xml-style empty tag
				|
					</[-a-zA-Z0-9:_]+\\s*> # closing tag
			') . '
				)
				}xs';
  while (1) {

    #

    # Each loop iteration seach for either the next tag, the next

    # openning code span marker, or the next escaped character.

    # Each token is then passed to handleSpanToken.

    #
    $parts = preg_split($span_re, $str, 2, PREG_SPLIT_DELIM_CAPTURE);

    # Create token from text preceding tag.
    if ($parts[0] != "") {
      $output .= $parts[0];
    }

    # Check if we reach the end.
    if (isset($parts[1])) {
      $output .= $this
        ->handleSpanToken($parts[1], $parts[2]);
      $str = $parts[2];
    }
    else {
      break;
    }
  }
  return $output;
}