You are here

function MarkdownExtra_Parser::doHeaders in Markdown 5

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

Overrides Markdown_Parser::doHeaders

File

./markdown.php, line 2185

Class

MarkdownExtra_Parser

Code

function doHeaders($text) {

  #

  # Redefined to add id attribute support.

  #

  # Setext-style headers:

  #	  Header 1  {#header1}

  #	  ========

  #

  #	  Header 2  {#header2}

  #	  --------

  #
  $text = preg_replace_callback('{
				(^.+?)								# $1: Header text
				(?:[ ]+\\{\\#([-_:a-zA-Z0-9]+)\\})?	# $2: Id attribute
				[ ]*\\n(=+|-+)[ ]*\\n+				# $3: Header footer
			}mx', array(
    &$this,
    '_doHeaders_callback_setext',
  ), $text);

  # atx-style headers:

  #	# Header 1        {#header1}

  #	## Header 2       {#header2}

  #	## Header 2 with closing hashes ##  {#header3}

  #	...

  #	###### Header 6   {#header2}

  #
  $text = preg_replace_callback('{
				^(\\#{1,6})	# $1 = string of #\'s
				[ ]*
				(.+?)		# $2 = Header text
				[ ]*
				\\#*			# optional closing #\'s (not counted)
				(?:[ ]+\\{\\#([-_:a-zA-Z0-9]+)\\})? # id attribute
				[ ]*
				\\n+
			}xm', array(
    &$this,
    '_doHeaders_callback_atx',
  ), $text);
  return $text;
}