Markdown_Parser::doCodeBlocks PHP 메소드

doCodeBlocks() 공개 메소드

public doCodeBlocks ( $text )
    function doCodeBlocks($text)
    {
        #
        #	Process Markdown `<pre><code>` blocks.
        #
        $text = preg_replace_callback('{
				(?:\\n\\n|\\A\\n?)
				(	            # $1 = the code block -- one or more lines, starting with a space/tab
				  (?>
					[ ]{' . $this->tab_width . '}  # Lines must start with a tab or a tab-width of spaces
					.*\\n+
				  )+
				)
				((?=^[ ]{0,' . $this->tab_width . '}\\S)|\\Z)	# Lookahead for non-space at line-start, or end of doc
			}xm', array(&$this, '_doCodeBlocks_callback'), $text);
        return $text;
    }

Usage Example

예제 #1
0
    function doCodeBlocks($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, '_doCodeBlocks_fenced_callback'), $text);
        $text = parent::doCodeBlocks($text);
        return $text;
    }