You are here

protected function MarkdownExtra::doFencedCodeBlocks in Markdown 7

* Adding the fenced code block syntax to regular Markdown: * * ~~~ * Code block * ~~~ * *

Parameters

string $text: * @return string

File

includes/MarkdownExtra.php, line 1406

Class

MarkdownExtra
Markdown Extra Parser Class

Namespace

Michelf

Code

protected function doFencedCodeBlocks($text) {
  $less_than_tab = $this->tab_width;
  $text = preg_replace_callback('{
				(?:\\n|\\A)
				# 1: Opening marker
				(
					(?:~{3,}|`{3,}) # 3 or more tildes/backticks.
				)
				[ ]*
				(?:
					\\.?([-_:a-zA-Z0-9]+) # 2: standalone class name
				)?
				[ ]*
				(?:
					' . $this->id_class_attr_catch_re . ' # 3: Extra attributes
				)?
				[ ]* \\n # Whitespace and newline following marker.
				
				# 4: Content
				(
					(?>
						(?!\\1 [ ]* \\n)	# Not a closing marker.
						.*\\n+
					)+
				)
				
				# Closing marker.
				\\1 [ ]* (?= \\n )
			}xm', array(
    $this,
    '_doFencedCodeBlocks_callback',
  ), $text);
  return $text;
}