You are here

function MarkdownExtra_Parser::doFencedCodeBlocks in Markdown 5

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

File

./markdown.php, line 2501

Class

MarkdownExtra_Parser

Code

function doFencedCodeBlocks($text) {

  #

  # Adding the fenced code block syntax to regular Markdown:

  #

  # ~~~

  # Code block

  # ~~~

  #
  $less_than_tab = $this->tab_width;
  $text = preg_replace_callback('{
				(?:\\n|\\A)
				# 1: Opening marker
				(
					~{3,} # Marker: three tilde or more.
				)
				[ ]* \\n # Whitespace and newline following marker.
				
				# 2: Content
				(
					(?>
						(?!\\1 [ ]* \\n)	# Not a closing marker.
						.*\\n+
					)+
				)
				
				# Closing marker.
				\\1 [ ]* \\n
			}xm', array(
    &$this,
    '_doFencedCodeBlocks_callback',
  ), $text);
  return $text;
}