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