You are here

protected function Markdown::doAnchors in Markdown 7

* Turn Markdown link shortcuts into XHTML <a> tags. *

Parameters

string $text: * @return string

1 method overrides Markdown::doAnchors()
MarkdownExtra::doAnchors in includes/MarkdownExtra.php
* Turn Markdown link shortcuts into XHTML <a> tags. *

File

includes/Markdown.php, line 654

Class

Markdown
Markdown Parser Class

Namespace

Michelf

Code

protected function doAnchors($text) {
  if ($this->in_anchor) {
    return $text;
  }
  $this->in_anchor = true;

  // First, handle reference-style links: [link text] [id]
  $text = preg_replace_callback('{
			(					# wrap whole match in $1
			  \\[
				(' . $this->nested_brackets_re . ')	# link text = $2
			  \\]

			  [ ]?				# one optional space
			  (?:\\n[ ]*)?		# one optional newline followed by spaces

			  \\[
				(.*?)		# id = $3
			  \\]
			)
			}xs', array(
    $this,
    '_doAnchors_reference_callback',
  ), $text);

  // Next, inline-style links: [link text](url "optional title")
  $text = preg_replace_callback('{
			(				# wrap whole match in $1
			  \\[
				(' . $this->nested_brackets_re . ')	# link text = $2
			  \\]
			  \\(			# literal paren
				[ \\n]*
				(?:
					<(.+?)>	# href = $3
				|
					(' . $this->nested_url_parenthesis_re . ')	# href = $4
				)
				[ \\n]*
				(			# $5
				  ([\'"])	# quote char = $6
				  (.*?)		# Title = $7
				  \\6		# matching quote
				  [ \\n]*	# ignore any spaces/tabs between closing quote and )
				)?			# title is optional
			  \\)
			)
			}xs', array(
    $this,
    '_doAnchors_inline_callback',
  ), $text);

  // Last, handle reference-style shortcuts: [link text]
  // These must come last in case you've also got [link text][1]
  // or [link text](/foo)
  $text = preg_replace_callback('{
			(					# wrap whole match in $1
			  \\[
				([^\\[\\]]+)		# link text = $2; can\'t contain [ or ]
			  \\]
			)
			}xs', array(
    $this,
    '_doAnchors_reference_callback',
  ), $text);
  $this->in_anchor = false;
  return $text;
}