1<?php 2// $Id: Paragraph.php,v 1.1 2005/01/31 15:46:52 pmjones Exp $ 3 4 5/** 6* 7* This class implements a Text_Wiki rule to find sections of the source 8* text that are paragraphs. A para is any line not starting with a token 9* delimiter, followed by two newlines. 10* 11* @author Paul M. Jones <pmjones@ciaweb.net> 12* 13* @package Text_Wiki 14* 15*/ 16 17class Text_Wiki_Parse_Paragraph extends Text_Wiki_Parse { 18 19 /** 20 * 21 * The regular expression used to find source text matching this 22 * rule. 23 * 24 * @access public 25 * 26 * @var string 27 * 28 */ 29 30 var $regex = "/^.*?\n\n/m"; 31 32 var $conf = array( 33 'skip' => array( 34 'blockquote', // are we sure about this one? 35 'code', 36 'heading', 37 'horiz', 38 'deflist', 39 'table', 40 'list', 41 'toc' 42 ) 43 ); 44 45 46 /** 47 * 48 * Generates a token entry for the matched text. Token options are: 49 * 50 * 'start' => The starting point of the paragraph. 51 * 52 * 'end' => The ending point of the paragraph. 53 * 54 * @access public 55 * 56 * @param array &$matches The array of matches from parse(). 57 * 58 * @return A delimited token number to be used as a placeholder in 59 * the source text. 60 * 61 */ 62 63 function process(&$matches) 64 { 65 $delim = $this->wiki->delim; 66 67 // was anything there? 68 if (trim($matches[0]) == '') { 69 return ''; 70 } 71 72 // does the match start with a delimiter? 73 if (substr($matches[0], 0, 1) != $delim) { 74 // no. 75 76 $start = $this->wiki->addToken( 77 $this->rule, array('type' => 'start') 78 ); 79 80 $end = $this->wiki->addToken( 81 $this->rule, array('type' => 'end') 82 ); 83 84 return $start . trim($matches[0]) . $end; 85 } 86 87 // the line starts with a delimiter. read in the delimited 88 // token number, check the token, and see if we should 89 // skip it. 90 91 // loop starting at the second character (we already know 92 // the first is a delimiter) until we find another 93 // delimiter; the text between them is a token key number. 94 $key = ''; 95 $len = strlen($matches[0]); 96 for ($i = 1; $i < $len; $i++) { 97 $char = $matches[0]{$i}; 98 if ($char == $delim) { 99 break; 100 } else { 101 $key .= $char; 102 } 103 } 104 105 // look at the token and see if it's skippable (if we skip, 106 // it will not be marked as a paragraph) 107 $token_type = strtolower($this->wiki->tokens[$key][0]); 108 $skip = $this->getConf('skip', array()); 109 110 if (in_array($token_type, $skip)) { 111 // this type of token should not have paragraphs applied to it. 112 // return the entire matched text. 113 return $matches[0]; 114 } else { 115 116 $start = $this->wiki->addToken( 117 $this->rule, array('type' => 'start') 118 ); 119 120 $end = $this->wiki->addToken( 121 $this->rule, array('type' => 'end') 122 ); 123 124 return $start . trim($matches[0]) . $end; 125 } 126 } 127} 128?>