You are here

function MarkdownExtra_Parser::processDefListItems in Markdown 5

Same name and namespace in other branches
  1. 6 markdown.php \MarkdownExtra_Parser::processDefListItems()
1 call to MarkdownExtra_Parser::processDefListItems()
MarkdownExtra_Parser::_doDefLists_callback in ./markdown.php

File

./markdown.php, line 2429

Class

MarkdownExtra_Parser

Code

function processDefListItems($list_str) {

  #

  #	Process the contents of a single definition list, splitting it

  #	into individual term and definition list items.

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

  # trim trailing blank lines:
  $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str);

  # Process definition terms.
  $list_str = preg_replace_callback('{
			(?>\\A\\n?|\\n\\n+)					# leading line
			(								# definition terms = $1
				[ ]{0,' . $less_than_tab . '}	# leading whitespace
				(?![:][ ]|[ ])				# negative lookahead for a definition
											#   mark (colon) or more whitespace.
				(?> \\S.* \\n)+?				# actual term (not whitespace).	
			)			
			(?=\\n?[ ]{0,3}:[ ])				# lookahead for following line feed
											#   with a definition mark.
			}xm', array(
    &$this,
    '_processDefListItems_callback_dt',
  ), $list_str);

  # Process actual definitions.
  $list_str = preg_replace_callback('{
			\\n(\\n+)?						# leading line = $1
			(								# marker space = $2
				[ ]{0,' . $less_than_tab . '}	# whitespace before colon
				[:][ ]+						# definition mark (colon)
			)
			((?s:.+?))						# definition text = $3
			(?= \\n+ 						# stop at next definition mark,
				(?:							# next term or end of text
					[ ]{0,' . $less_than_tab . '} [:][ ]	|
					<dt> | \\z
				)						
			)					
			}xm', array(
    &$this,
    '_processDefListItems_callback_dd',
  ), $list_str);
  return $list_str;
}