You are here

protected function Markdown::processListItems in Express 8

* Process the contents of a single ordered or unordered list, splitting it * into individual list items. *

Parameters

string $list_str: * @param string $marker_any_re * @return string

1 call to Markdown::processListItems()
Markdown::_doLists_callback in vendor/michelf/php-markdown/Michelf/Markdown.php
* List parsing callback *

File

vendor/michelf/php-markdown/Michelf/Markdown.php, line 1113

Class

Markdown
Markdown Parser Class

Namespace

Michelf

Code

protected function processListItems($list_str, $marker_any_re) {

  /**
   * The $this->list_level global keeps track of when we're inside a list.
   * Each time we enter a list, we increment it; when we leave a list,
   * we decrement. If it's zero, we're not in a list anymore.
   *
   * We do this because when we're not inside a list, we want to treat
   * something like this:
   *
   *		I recommend upgrading to version
   *		8. Oops, now this line is treated
   *		as a sub-list.
   *
   * As a single paragraph, despite the fact that the second line starts
   * with a digit-period-space sequence.
   *
   * Whereas when we're inside a list (or sub-list), that line will be
   * treated as the start of a sub-list. What a kludge, huh? This is
   * an aspect of Markdown's syntax that's hard to parse perfectly
   * without resorting to mind-reading. Perhaps the solution is to
   * change the syntax rules such that sub-lists must start with a
   * starting cardinal number; e.g. "1." or "a.".
   */
  $this->list_level++;

  // Trim trailing blank lines:
  $list_str = preg_replace("/\n{2,}\\z/", "\n", $list_str);
  $list_str = preg_replace_callback('{
			(\\n)?							# leading line = $1
			(^[ ]*)							# leading whitespace = $2
			(' . $marker_any_re . '				# list marker and space = $3
				(?:[ ]+|(?=\\n))	# space only required if item is not empty
			)
			((?s:.*?))						# list item text   = $4
			(?:(\\n+(?=\\n))|\\n)				# tailing blank line = $5
			(?= \\n* (\\z | \\2 (' . $marker_any_re . ') (?:[ ]+|(?=\\n))))
			}xm', array(
    $this,
    '_processListItems_callback',
  ), $list_str);
  $this->list_level--;
  return $list_str;
}