1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
| | #freeze
TITLE:複数行インラインプラグイン
#indent
#contents
- インラインプラグインの引数が長くなると改行が必要になる。
-- 特に TeX を利用している ##eq## とか。
- 複数行ブロックプラグインを真似て同じ構文で複数行インラインプラグインを導入。
- 引数展開もブロックプラグインに準じて非展開。
-- 技術上、従来のインラインプラグインのように引数を展開するのは困難。
-- TeX などの場合、引数非展開の方が好都合。
>##$##'''plugin''' ##(##'''arg''' ##){{&br; ##'''body'''&br;##}}##
<で、
>##&##'''plugin''' ##(##'''arg'''##,##'''body''' ##)##
<と同等の振る舞い。
- 引数の処理は複数行ブロックプラグインに準ずる。
-- '''arg''' と'''body''' は引数非展開。
-- '''body''' の前、各行末は ##"\r" ##を挿入。
- ##lib/convert_html.php## にて、##function & Factory_Div## をコピーし、##function & Factory_Span## に改造。
-- 「##!##」の行は ##function Factory_Div## からの差分。
--- ##&#;## の正規表現を ##\$## に、##new Div## を ##new Span## に置換。
-
#code(diff){{{{
!function & Factory_Span(& $root, $text)
{
$matches = array();
if (PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) {
! if (preg_match('/^\$([^\(]+)(?:\((.*)\))?/', $text, $matches) &&
exist_plugin_convert($matches[1])) {
! return new Inline($matches);
}
} else {
! if(preg_match('/^\$([^\(\{]+)(?:\(([^\r]*)\))?(\{*)/', $text, $matches) &&
exist_plugin_inline($matches[1])) {
$len = strlen($matches[3]);
$body = array();
if ($len == 0) {
return new Span($matches); // Seems legacy block plugin
} else if (preg_match('/\{{' . $len . '}\s*\r(.*)\s*\}{' . $len . '}/', $text, $body)) {
$matches[2] .= $body[1];
return new Span($matches); // Seems multiline-enabled block plugin
}
}
}
return new Inline($text);
}
}}}}
-
- 同ファイルの ##class Div## をコピーし、##class Span## に改造。
-- 「##!##」の行は ##class Div## からの差分。
-- 「##+##」の行は ##class Inline## からのコピー。
--- これらは、インラインプラグインで始まる文を、後に段落に昇格させるための関数。
-
#code(diff){{{{
!// $something (started with '$') for Multiline-enabled Argment-keeping Inline-plugin
!class Span extends Element
{
var $name;
var $param;
! function Span($out)
{
parent::Element();
list(, $this->name, $this->param) = array_pad($out, 3, '');
}
function canContain(& $obj)
{
return FALSE;
}
+ function & insert(& $obj)
+ {
+ $this->elements[] = $obj->elements[0];
+ return $this;
+ }
function toString()
{
! return do_plugin_inline($this->name, $this->param);
}
+ function & toPara($class = '')
+ {
+ $obj = & new Paragraph('', $class);
+ $obj->insert($this);
+ return $obj;
+ }
}
}}}}
- 同ファイル、##class Body##の##var $factories##に対し、
-
#code(diff){{{{
var $factories = array(
':' => 'DList',
'|' => 'Table',
',' => 'YTable',
- '#' => 'Div');
+ '#' => 'Div',
+ '$' => 'Span');
}}}}
- 同クラス ##class Body## の ##function parse##の複数行ブロックプラグインの分岐をコピーして改造。
-- 「##!##」はコピー元に対する変更。
-- 丸引数の有無をチェックし、波引数との間の「##,##」の有無を調節。
-
#code(diff){{{{
! // Multiline-enabled Argment-keeping Inline-plugin
if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK &&
! preg_match('/^\$[^({]*(\((.*)\))?(\{\{+)\s*$/', $line, $matches)) {
$delimiter = "\r";
! $len = strlen($matches[3]);
! $line .= ($matches[2] == '') ? $delimiter : ','.$delimiter;
while (! empty($lines)) {
$next_line = rtrim(array_shift($lines), "\r\n");
if ($indent_format)
{
preg_match('/^(\s{'.$indent.'}?)?(.*)$/', $next_line, $matches);
$next_line = $matches[2];
}
if (preg_match('/\s*\}{' . $len . '}/', $next_line)) {
$line .= ltrim($next_line);
break;
} else {
$line .= $next_line . $delimiter;
}
}
}
}}}}
- 複数行インラインプラグインをインライン要素と同じ振る舞いさせるため、~
同ファイル中の「##is_a($obj, 'Inline')##」を「##is_a($obj, 'Inline') || is_a($obj, 'Span')##」に置換。
-- ただし、##class Inline## の ##function canContain## だけは変えてはダメ。(理由は説明できないが、経験則)
-- 同ファイル、##class Paragraph## と ##class Align## のそれぞれの ##function canContain## にて、
--
#code(diff){{{{
function canContain($obj)
{
- return is_a($obj, 'Inline');
+ return is_a($obj, 'Inline') || is_a($obj, 'Span');
}
}}}}
-- 同クラス ##class Body## の ##function & insert##にて、
--
#code(diff){{{{
function & insert(& $obj)
{
- if (is_a($obj, 'Inline')) $obj = & $obj->toPara();
+ if (is_a($obj, 'Inline') || is_a($obj, 'Span')) $obj = & $obj->toPara();
return parent::insert($obj);
}
}}}}
-- 同ファイル、##class BQuote## の ##function & insert## にて、
--
#code(diff){{{{
function & insert(& $obj)
{
- if (is_a($obj, 'inline'))
+ if (is_a($obj, 'inline') || is_a($obj, 'Span'))
return parent::insert($obj->toPara(' class="quotation"'));
}}}}
- プラグインの書式
-- 第1案:先頭1字で書式決定
--- 既存の「##&#;##」と「##&&;##」の間を日本語キーボード配列順(=ASCII順)に補間。
--
|* |*引数非展開 |< |*引数展開 |< |
|^ |*ブロック |*インライン |*ブロック |*インライン |
|*単一行|###〜(〜){〜}; ## |##$〜(〜){〜}; ## |##&%;〜(〜){〜}; ## |##&〜(〜{〜}; ## |
|*複数行|###〜(〜){{&br;〜&br;}}##|##$〜(〜){{&br;〜&br;}}##|##&%;〜(〜){{&br;〜&br;}}##|##&〜(〜){{&br;〜&br;}}##|
-- 第2案:先頭1字でブロック/インラインを決定、第2字で引数展開/非展開を決定。
--- 既存の「##&#;##」と「##&&;##」のみで解決。
--- 「##&#;##」と「##&&;##」はそれぞれ「##&#;&#;##」と「##&&;&&;##」の省略的扱い。
--
|* |*ブロック |< |*インライン |< |
|^ |*引数非展開 |*引数展開 |*引数非展開 |*引数展開 |
|*単一行|##&#;#〜(〜){〜};## |###&〜(〜){〜};## |##&#〜(〜){〜};## |##&&〜(〜{〜};## |
|*複数行|##&#;#〜(〜){{&br;〜&br;}}##|###&〜(〜){{&br;〜&br;}}##|##&#〜(〜){{&br;〜&br;}}##|##&&〜(〜){{&br;〜&br;}}##|
|