You are here

function Markdown_Parser::stripLinkDefinitions in Markdown 5

Same name and namespace in other branches
  1. 6 markdown.php \Markdown_Parser::stripLinkDefinitions()

File

./markdown.php, line 331

Class

Markdown_Parser

Code

function stripLinkDefinitions($text) {

  #

  # Strips link definitions from text, stores the URLs and titles in

  # hash references.

  #
  $less_than_tab = $this->tab_width - 1;

  # Link defs are in the form: ^[id]: url "optional title"
  $text = preg_replace_callback('{
							^[ ]{0,' . $less_than_tab . '}\\[(.+)\\][ ]?:	# id = $1
							  [ ]*
							  \\n?				# maybe *one* newline
							  [ ]*
							<?(\\S+?)>?			# url = $2
							  [ ]*
							  \\n?				# maybe one newline
							  [ ]*
							(?:
								(?<=\\s)			# lookbehind for whitespace
								["(]
								(.*?)			# title = $3
								[")]
								[ ]*
							)?	# title is optional
							(?:\\n+|\\Z)
			}xm', array(
    &$this,
    '_stripLinkDefinitions_callback',
  ), $text);
  return $text;
}