1 |
wakaba |
1.1 |
#?SuikaWikiConfig/2.0 |
2 |
|
|
|
3 |
|
|
Plugin: |
4 |
|
|
@Name: SuikaWiki09 |
5 |
|
|
@Description: |
6 |
|
|
@@@: SuikaWiki/0.9 document format |
7 |
|
|
@@lang:en |
8 |
|
|
@License: %%GPL%% |
9 |
|
|
@Author: |
10 |
|
|
@@Name: |
11 |
|
|
@@@@: Wakaba |
12 |
|
|
@@@lang:ja |
13 |
|
|
@@@script:Latn |
14 |
|
|
@@Mail[list]: w@suika.fam.cx |
15 |
wakaba |
1.7 |
@Date.RCS: |
16 |
|
|
$Date: 2004/02/08 08:49:05 $ |
17 |
wakaba |
1.1 |
@RequiredPlugin[list]: |
18 |
wakaba |
1.4 |
Edit |
19 |
|
|
WikiFormCore |
20 |
wakaba |
1.2 |
WikiLinking |
21 |
wakaba |
1.4 |
WikiStruct |
22 |
wakaba |
1.1 |
@Use: |
23 |
|
|
use Message::Markup::XML::QName qw/NS_xml_URI/; |
24 |
|
|
my $Reg_Form_Content_M = qr{ |
25 |
|
|
\ \#form |
26 |
|
|
\ (?: |
27 |
|
|
\ \( (\w+) \) ## id |
28 |
|
|
\ )? |
29 |
|
|
\ : ' ((?>[^\\']*)(?>(?>[^\\']+|\\.)*)) ' ## input |
30 |
|
|
\ (?: : ' ((?>[^\\']*)(?>(?>[^\\']+|\\.)*)) ' ## template |
31 |
|
|
\ (?: : ' ((?>[^\\']*)(?>(?>[^\\']+|\\.)*)) ' )? )? ## option |
32 |
|
|
}x; |
33 |
|
|
my $Reg_Embed_Content_M = qr{ |
34 |
|
|
\ \#([a-z-]+) |
35 |
|
|
\ (?> |
36 |
|
|
\ \( (\w+) \) ## id |
37 |
|
|
\ )? |
38 |
|
|
\ (?> |
39 |
|
|
\ : ( \w+ (?> : \w+ )* ) ## parameter |
40 |
|
|
\ )? |
41 |
|
|
}x; |
42 |
|
|
my $Reg_URI_Opaque = qr{ |
43 |
|
|
\ (?>[^<>"]*) |
44 |
|
|
\ (?> |
45 |
|
|
\ (?> |
46 |
|
|
\ [^<>"]+ |
47 |
|
|
\ | "(?>[^"\\]*)(?>(?>[^"\\]+|\\.)*)" |
48 |
|
|
\ )* |
49 |
|
|
\ ) |
50 |
|
|
}x; |
51 |
wakaba |
1.5 |
my $WIKIRESOURCE; |
52 |
wakaba |
1.1 |
|
53 |
wakaba |
1.2 |
PluginConst: |
54 |
|
|
@NS_SW09: |
55 |
|
|
urn:x-suika-fam-cx:markup:suikawiki:0:9: |
56 |
|
|
@NS_HTML3: |
57 |
|
|
urn:x-suika-fam-cx:markup:ietf:html:3:draft:00: |
58 |
|
|
@NS_XHTML1: |
59 |
|
|
http://www.w3.org/1999/xhtml |
60 |
|
|
@NS_XHTML2: |
61 |
|
|
http://www.w3.org/2002/06/xhtml2 |
62 |
wakaba |
1.5 |
@WIKIRESOURCE: |
63 |
|
|
{($WIKIRESOURCE ||= SuikaWiki::Plugin->module_package ('WikiResource'))} |
64 |
wakaba |
1.2 |
|
65 |
wakaba |
1.1 |
Format: |
66 |
|
|
@ModuleName: |
67 |
|
|
SuikaWiki::V0 |
68 |
|
|
@Description: |
69 |
|
|
@@@: Dummy base format for SuikaWiki/0.* |
70 |
|
|
@@lang:en |
71 |
|
|
@Inherit[list]: |
72 |
|
|
Text::Plain |
73 |
|
|
|
74 |
|
|
Format: |
75 |
|
|
@Name: SuikaWiki |
76 |
|
|
@Version: 0.9 |
77 |
|
|
@Type: |
78 |
|
|
@@@: text/x-suikawiki |
79 |
|
|
@@version: 0.9 |
80 |
|
|
@ModuleName: |
81 |
|
|
SuikaWiki::V0_9 |
82 |
|
|
@Inherit[list]: |
83 |
|
|
SuikaWiki::V0 |
84 |
|
|
@Description: |
85 |
|
|
@@@: SuikaWiki/0.9 document format (Standard document format for SuikaWiki 2) |
86 |
|
|
@@lang:en |
87 |
wakaba |
1.2 |
|
88 |
|
|
@Use: |
89 |
|
|
use Message::Markup::XML::QName qw/NS_xml_URI/; |
90 |
wakaba |
1.4 |
use Message::Util::Error; |
91 |
wakaba |
1.1 |
|
92 |
|
|
@Converter: |
93 |
|
|
@@Type: text/html |
94 |
|
|
@@IsFragment: 1 |
95 |
|
|
@@Description: |
96 |
|
|
@@@@: Converting SuikaWiki/0.9 to Hypertext Markup Language fragment |
97 |
|
|
@@@lang:en |
98 |
|
|
@@Main: |
99 |
wakaba |
1.4 |
$opt->{o}->{wiki} ||= $self->{wiki}; |
100 |
|
|
|
101 |
wakaba |
1.2 |
## Text format -> XML format |
102 |
wakaba |
1.4 |
my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => $opt, |
103 |
|
|
wiki => $self->{wiki}); |
104 |
|
|
|
105 |
|
|
## SuikaWiki/0.9 -> XHTML 1 |
106 |
wakaba |
1.6 |
__FUNCPACK__->sw09_to_xhtml1 (source => $xml, parent => $opt->{-parent}, |
107 |
|
|
o => $opt->{o}, page => $opt->{page}); |
108 |
|
|
|
109 |
|
|
if ($opt->{-with_annotation_input}) { |
110 |
|
|
SuikaWiki::Plugin->module_package ('WikiFormCore') |
111 |
|
|
->make_content_form_in_html |
112 |
|
|
($opt->{-parent}, |
113 |
|
|
$WIKIRESOURCE->get |
114 |
|
|
(name => 'SuikaWiki/0.9:form:footannotate:input', |
115 |
|
|
o => $opt->{o}, wiki => $opt->{o}->{wiki}), |
116 |
|
|
option => $WIKIRESOURCE->get |
117 |
|
|
(name => 'SuikaWiki/0.9:form:footannotate:option', |
118 |
|
|
o => $opt->{o}, wiki => $opt->{o}->{wiki}), |
119 |
|
|
o => $opt->{o}, |
120 |
|
|
wiki => $opt->{o}->{wiki}, |
121 |
|
|
output => { |
122 |
|
|
page => $opt->{page}, |
123 |
|
|
}); |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
|
127 |
|
|
@Converter: |
128 |
|
|
@@Type: |
129 |
|
|
@@@@: application/x-suikawiki+xml |
130 |
|
|
@@@version: 0.9 |
131 |
|
|
@@Description: |
132 |
|
|
@@@@: Converting SuikaWiki/0.9 text format to XML format |
133 |
|
|
@@@lang: en |
134 |
|
|
@@Main: |
135 |
|
|
my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => $opt, |
136 |
|
|
wiki => $self->{wiki}); |
137 |
|
|
## TODO: Make a clone |
138 |
|
|
$opt->{-parent}->append_node ($xml); |
139 |
|
|
|
140 |
|
|
@NextIndex: |
141 |
|
|
@@Name: anchor |
142 |
|
|
@@Main: |
143 |
|
|
my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt, |
144 |
|
|
wiki => $self->{wiki}); |
145 |
|
|
(__FUNCPACK__->get_last_anchor_index ($xml)) + 1; |
146 |
|
|
|
147 |
|
|
@WikiForm: |
148 |
|
|
@@Main: |
149 |
|
|
## Text format -> XML format |
150 |
|
|
my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt, |
151 |
|
|
wiki => $self->{wiki}); |
152 |
|
|
local $opt{o}->{var}->{sw09__anchor_index}; |
153 |
|
|
local $opt{o}->{var}->{sw09__document_tree} = $xml; |
154 |
|
|
|
155 |
|
|
my $form; |
156 |
|
|
if ($opt{o}->{form}->{output}->{id}) { |
157 |
|
|
$form = __FUNCPACK__->get_element_by_id |
158 |
|
|
($xml, $opt{o}->{form}->{output}->{id}); |
159 |
|
|
undef $form unless ref $form and |
160 |
|
|
$form->namespace_uri eq $NS_SW09 and |
161 |
|
|
$form->local_name eq 'form'; |
162 |
|
|
} else { |
163 |
|
|
$form = __FUNCPACK__->get_nth_element |
164 |
|
|
($xml, $NS_SW09 => 'form', |
165 |
|
|
$opt{o}->{form}->{output}->{index}); |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
my $ref; |
169 |
|
|
if (ref $form) { |
170 |
|
|
$ref = $form->get_attribute_value ('ref', default => 'form'); |
171 |
|
|
} else { |
172 |
|
|
$ref = '#footannotate'; |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
|
176 |
|
|
## WikiForm Option |
177 |
|
|
if ($ref eq 'form') { |
178 |
|
|
$opt{option} ||= $form->get_attribute_value ('option'); |
179 |
|
|
} elsif ($ref eq 'comment') { |
180 |
|
|
$opt{option} ||= $WIKIRESOURCE->get |
181 |
|
|
(name => 'SuikaWiki/0.9:form:comment:option', |
182 |
|
|
o => $opt{o}, wiki => $opt{o}->{wiki}); |
183 |
|
|
} elsif ($ref eq '#footannotate') { |
184 |
|
|
$opt{option} ||= $WIKIRESOURCE->get |
185 |
|
|
(name => 'SuikaWiki/0.9:form:footannotate:option', |
186 |
|
|
o => $opt{o}, wiki => $opt{o}->{wiki}); |
187 |
|
|
} else { |
188 |
|
|
## TODO: |
189 |
|
|
} |
190 |
|
|
SuikaWiki::Plugin->module_package ('WikiFormCore') |
191 |
|
|
->set_option ($opt{option} => $opt{o}) if $opt{option}; |
192 |
|
|
|
193 |
|
|
## Replace Output Template |
194 |
|
|
my $result; |
195 |
|
|
if ($ref eq 'form') { |
196 |
|
|
$opt{template} ||= $form->get_attribute_value |
197 |
|
|
('template', default => ''); |
198 |
|
|
} elsif ($ref eq 'comment') { |
199 |
|
|
$opt{template} ||= $WIKIRESOURCE->get |
200 |
|
|
(name => 'SuikaWiki/0.9:form:comment:template', |
201 |
|
|
o => $opt{o}, wiki => $opt{o}->{wiki}); |
202 |
|
|
} elsif ($ref eq '#footannotate') { |
203 |
|
|
$opt{template} ||= $WIKIRESOURCE->get |
204 |
|
|
(name => 'SuikaWiki/0.9:form:footannotate:template', |
205 |
|
|
o => $opt{o}, wiki => $opt{o}->{wiki}); |
206 |
|
|
} |
207 |
|
|
try { |
208 |
|
|
$result = SuikaWiki::Plugin->text_formatter ('form_template') |
209 |
|
|
->replace ($opt{template}, param => $opt{o}); |
210 |
|
|
} catch Message::Util::Formatter::error with { |
211 |
|
|
my $err = shift; |
212 |
|
|
SuikaWiki::Plugin->module_package ('Error') |
213 |
|
|
->reporting_formatting_template_error |
214 |
|
|
($err, $err->{option}->{param}->{wiki}); |
215 |
|
|
##TODO: |
216 |
|
|
throw SuikaWiki::View::Implementation::error -type => 'ERROR_REPORTED'; |
217 |
|
|
}; |
218 |
|
|
|
219 |
|
|
## Insert |
220 |
|
|
if (length $result) { |
221 |
|
|
if ($ref eq '#footannotate') { |
222 |
|
|
my $parent; |
223 |
|
|
for (@{$xml->child_nodes}) { |
224 |
|
|
if ($_->node_type eq '#element' and |
225 |
|
|
$_->local_name eq 'document') { |
226 |
|
|
for (@{$_->child_nodes}) { |
227 |
|
|
if ($_->node_type eq '#element' and |
228 |
|
|
$_->local_name eq 'body') { |
229 |
|
|
$parent = $_; |
230 |
|
|
last; |
231 |
|
|
} |
232 |
|
|
} |
233 |
|
|
} |
234 |
|
|
} |
235 |
|
|
CORE::die "Buggy implementation: no body element".$xml unless ref $parent; |
236 |
|
|
|
237 |
|
|
$parent->append_new_node (type => '#element', |
238 |
|
|
namespace_uri => $NS_SW09, |
239 |
|
|
local_name => 'text') |
240 |
|
|
->append_text ($result); |
241 |
|
|
} else { |
242 |
|
|
my $parent = $form->parent_node; |
243 |
|
|
CORE::die "Byggy implementation: No parent of form" unless ref $parent; |
244 |
|
|
my $children = $parent->child_nodes; |
245 |
|
|
|
246 |
|
|
$result .= "\x0A" unless substr ($result, -1) eq "\x0A"; |
247 |
|
|
$parent->append_new_node (type => '#element', |
248 |
|
|
namespace_uri => $NS_SW09, |
249 |
|
|
local_name => 'text') |
250 |
|
|
->append_text ($result); |
251 |
|
|
my $node = pop @{$children}; |
252 |
|
|
my $form_str = overload::StrVal ($form); |
253 |
|
|
my $i = 0; |
254 |
|
|
for (@{$children}) { |
255 |
|
|
last if overload::StrVal ($_) eq $form_str; |
256 |
|
|
$i++; |
257 |
|
|
} |
258 |
|
|
if ($opt{o}->{form}->{output}->{reverse}) { |
259 |
|
|
splice @{$children}, $i + 1, 0, $node; |
260 |
|
|
} else { |
261 |
|
|
splice @{$children}, $i, 0, $node; |
262 |
|
|
} |
263 |
|
|
} |
264 |
|
|
} else { |
265 |
|
|
## TODO: |
266 |
|
|
} |
267 |
|
|
|
268 |
|
|
## XML format -> Text format |
269 |
|
|
my $text = __FUNCPACK__->xml_to_text ($xml, {%opt}); |
270 |
|
|
|
271 |
|
|
my %fragment = (fragment => $opt{o}->{form}->{output}->{id} |
272 |
|
|
|| 'wikiform-'.$opt{o}->{form}->{output}->{index}); |
273 |
|
|
if (not $opt{o}->{form}->{output}->{reverse} and |
274 |
|
|
$opt{o}->{var}->{sw09__anchor_index}) { |
275 |
|
|
%fragment = (anchor_no => $opt{o}->{var}->{sw09__anchor_index}); |
276 |
|
|
} |
277 |
|
|
|
278 |
|
|
my $action = [ |
279 |
|
|
{ |
280 |
|
|
type => 'write', |
281 |
|
|
content => $text, |
282 |
|
|
update_lastmodified => time, |
283 |
|
|
}, |
284 |
|
|
{ |
285 |
|
|
type => 'view', |
286 |
|
|
%fragment, |
287 |
|
|
}, |
288 |
|
|
]; |
289 |
|
|
|
290 |
|
|
@HeadSummary: |
291 |
|
|
@@Main: |
292 |
|
|
my $xml = __FUNCPACK__->get_xml_tree (text => $source, opt => \%opt, |
293 |
|
|
wiki => $self->{wiki}); |
294 |
|
|
return $xml->inner_text; |
295 |
|
|
|
296 |
|
|
FormattingRule: |
297 |
|
|
@Category[list]:form-template |
298 |
|
|
@Name: index |
299 |
|
|
@Description: |
300 |
|
|
@@@: Next anchor index number |
301 |
|
|
@@lang:en |
302 |
|
|
@After: |
303 |
|
|
if ($o->{var}->{sw09__anchor_index}) { |
304 |
|
|
++$o->{var}->{sw09__anchor_index}; |
305 |
|
|
} else { |
306 |
|
|
$o->{var}->{sw09__anchor_index} |
307 |
|
|
= 1 + __FUNCPACK__->get_last_anchor_index |
308 |
|
|
($o->{var}->{sw09__document_tree}); |
309 |
|
|
} |
310 |
|
|
$p->{-result} .= $o->{var}->{sw09__anchor_index}; |
311 |
|
|
|
312 |
|
|
Function: |
313 |
|
|
@Name: get_last_anchor_index |
314 |
|
|
@Main: |
315 |
|
|
my (undef, $xml) = @_; |
316 |
|
|
my $anchor = 0; |
317 |
|
|
my $get_anchor_no; |
318 |
|
|
$get_anchor_no = sub { |
319 |
|
|
my $node = shift; |
320 |
|
|
for my $child (@{$node->child_nodes}) { |
321 |
|
|
if ($child->node_type eq '#element') { |
322 |
|
|
if ($child->namespace_uri => $NS_SW09 and |
323 |
|
|
$child->local_name eq 'anchor-end') { |
324 |
|
|
my $a = $child->get_attribute_value ('anchor', default => 0, |
325 |
|
|
namespace_uri => $NS_SW09); |
326 |
|
|
$anchor = 0+$a if $anchor < 0+$a; |
327 |
|
|
} else { |
328 |
|
|
$get_anchor_no->($child); |
329 |
|
|
} |
330 |
|
|
} elsif ($child->node_type eq '#document' or |
331 |
|
|
$child->node_type eq '#fragment') { |
332 |
|
|
$get_anchor_no->($child); |
333 |
|
|
} |
334 |
|
|
} |
335 |
|
|
}; |
336 |
|
|
$get_anchor_no->($xml); |
337 |
|
|
$anchor; |
338 |
|
|
|
339 |
|
|
|
340 |
|
|
Function: |
341 |
|
|
@Name: get_xml_tree |
342 |
|
|
@Main: |
343 |
|
|
my (undef, %opt) = @_; |
344 |
|
|
if ($opt{opt}->{page}) { |
345 |
|
|
unless ($__FUNCPACK__::DBLoaded) { |
346 |
|
|
$opt{wiki}->{db}->_set_prop_db (sw09__xml_tree => {-db_open => sub { |
347 |
|
|
require SuikaWiki::DB::Hash; |
348 |
|
|
new SuikaWiki::DB::Hash; |
349 |
|
|
}}); |
350 |
|
|
$__FUNCPACK__::DBLoaded++; |
351 |
|
|
} |
352 |
|
|
|
353 |
|
|
my $xml = new Message::Markup::XML::Node type => '#fragment'; |
354 |
|
|
__FUNCPACK__->text_to_xml (${$opt{text}}, {%{$opt{opt}}, -parent => $xml}); |
355 |
|
|
|
356 |
|
|
$opt{wiki}->{db}->set (sw09__xml_tree => $opt{opt}->{page} => $xml); |
357 |
|
|
$xml; |
358 |
|
|
} else { |
359 |
|
|
my $xml = new Message::Markup::XML::Node type => '#fragment'; |
360 |
|
|
__FUNCPACK__->text_to_xml (${$opt{text}}, {%{$opt{opt}}, -parent => $xml}); |
361 |
|
|
$xml; |
362 |
|
|
} |
363 |
|
|
|
364 |
|
|
Function: |
365 |
|
|
@Name: sw09_to_xhtml1 |
366 |
|
|
@Main: |
367 |
|
|
my (undef, %opt) = @_; |
368 |
|
|
|
369 |
wakaba |
1.2 |
my ($apply_template, $apply_template_children); |
370 |
|
|
$apply_template_children = sub { |
371 |
|
|
my ($parent, $result) = @_; |
372 |
|
|
for (@{$parent->child_nodes}) { |
373 |
|
|
$apply_template->($_ => $result) unless $_->node_type eq '#attribute'; |
374 |
|
|
} |
375 |
|
|
}; |
376 |
|
|
$apply_template = sub { |
377 |
|
|
my ($source, $result) = @_; |
378 |
|
|
my $ln = $source->local_name; |
379 |
|
|
if ($source->node_type eq '#text') { |
380 |
|
|
$result->append_text ($source->inner_text); |
381 |
|
|
} elsif ({qw/code 1 samp 1 var 1 dfn 1 kbd 1 sub 1 sup 1/}->{$ln}) { |
382 |
|
|
my $node = $result->append_new_node |
383 |
|
|
(type => '#element', |
384 |
|
|
namespace_uri => $NS_XHTML1, |
385 |
|
|
local_name => $ln); |
386 |
|
|
my $class = $source->get_attribute_value ('class', default => ''); |
387 |
|
|
$node->set_attribute (class => $class) if $class; |
388 |
|
|
$apply_template_children->($source => $node); |
389 |
wakaba |
1.4 |
} elsif ({qw/ins 1 del 1 insert 1 delete 1/}->{$ln}) { |
390 |
wakaba |
1.2 |
my $node = $result->append_new_node |
391 |
|
|
(type => '#element', |
392 |
|
|
namespace_uri => $NS_XHTML1, |
393 |
wakaba |
1.4 |
local_name => {qw/ins ins insert ins |
394 |
|
|
delete del del del/}->{$ln}); |
395 |
wakaba |
1.2 |
my $class = $source->get_attribute_value ('class', default => ''); |
396 |
|
|
$node->set_attribute (class => $class) if $class; |
397 |
|
|
## TODO: cite |
398 |
|
|
$apply_template_children->($source => $node); |
399 |
|
|
} elsif ({qw/table 1 tbody 1 tr 1 td 1 blockquote 1 ul 1 ol 1 |
400 |
|
|
li 1 pre 1 dl 1 dt 1 dd 1 em 1 strong 1/}->{$ln}) { |
401 |
|
|
my $node = $result->append_new_node |
402 |
|
|
(type => '#element', |
403 |
|
|
namespace_uri => $NS_XHTML1, |
404 |
|
|
local_name => $ln); |
405 |
|
|
if ($ln eq 'td') { |
406 |
|
|
my $colspan = $source->get_attribute_value ('colspan', default => 0); |
407 |
|
|
$node->set_attribute (colspan => $colspan) if $colspan; |
408 |
|
|
} elsif ($ln eq 'pre') { |
409 |
|
|
$node->set_attribute (space => 'preserve', |
410 |
|
|
namespace_uri => NS_xml_URI); |
411 |
|
|
} |
412 |
wakaba |
1.6 |
$apply_template_children->($source => $node); |
413 |
|
|
} elsif ($ln eq 'anchor') { |
414 |
|
|
local $opt{o}->{var}->{sw09__anchor_content} = sub { |
415 |
|
|
$apply_template_children->($source => shift); |
416 |
|
|
}; |
417 |
|
|
SuikaWiki::Plugin->module_package ('WikiLinking') |
418 |
|
|
->to_wikipage_in_html ({ |
419 |
|
|
label => SuikaWiki::Plugin->module_package ('WikiResource') |
420 |
|
|
->get_text |
421 |
|
|
(name => |
422 |
|
|
'Link:SuikaWiki/0.9:toWikiPage:SourceLabel', |
423 |
|
|
param => $opt{o}, |
424 |
|
|
wiki => $opt{o}->{wiki}), |
425 |
|
|
} => { |
426 |
|
|
base => $opt{o}->{wiki}->{var}->{page}, |
427 |
|
|
page_name_relative => $opt{o}->{wiki}->name ($source->inner_text), |
428 |
|
|
page_anchor_no => $source->get_attribute_value |
429 |
|
|
('anchor', |
430 |
|
|
namespace_uri => $NS_SW09), |
431 |
|
|
}, { |
432 |
|
|
o => $opt{o}, |
433 |
|
|
parent => $result, |
434 |
|
|
}); |
435 |
|
|
} elsif ($ln eq 'p') { |
436 |
|
|
$apply_template_children->($source => $result->append_new_node |
437 |
wakaba |
1.2 |
(type => '#element', |
438 |
|
|
namespace_uri => $NS_XHTML1, |
439 |
wakaba |
1.6 |
local_name => 'p')); |
440 |
|
|
} elsif ($ln eq 'h') { |
441 |
|
|
my $node; |
442 |
|
|
if ($opt{o}->{var}->{ws__section_depth} > 6) { |
443 |
|
|
$node = $result->append_new_node |
444 |
wakaba |
1.2 |
(type => '#element', |
445 |
|
|
namespace_uri => $NS_XHTML1, |
446 |
wakaba |
1.6 |
local_name => 'div'); |
447 |
|
|
$node->set_attribute (class => 'heading h'.$opt{o}->{var} |
448 |
|
|
->{ws__section_depth}); |
449 |
|
|
} else { |
450 |
|
|
$node = $result->append_new_node |
451 |
wakaba |
1.2 |
(type => '#element', |
452 |
|
|
namespace_uri => $NS_XHTML1, |
453 |
wakaba |
1.6 |
local_name => 'h'.$opt{o}->{var} |
454 |
|
|
->{ws__section_depth}); |
455 |
wakaba |
1.2 |
} |
456 |
|
|
$apply_template_children->($source => $node); |
457 |
wakaba |
1.6 |
SuikaWiki::Plugin->module_package ('WikiStruct') |
458 |
|
|
->set_section_id ($result, undef, $opt{o}->{wiki}, |
459 |
|
|
title => $source->inner_text); |
460 |
|
|
} elsif ($ln eq 'ruby' or $ln eq 'rubyb') { |
461 |
|
|
my @child; |
462 |
|
|
for (@{$source->child_nodes}) { |
463 |
|
|
if ({qw/rb 1 rt 1/}->{$_->local_name}) { |
464 |
|
|
push @child, $_; |
465 |
|
|
} |
466 |
|
|
} |
467 |
|
|
for ($result->append_new_node (type => '#element', |
468 |
|
|
namespace_uri => $NS_XHTML1, |
469 |
|
|
local_name => 'ruby')) { |
470 |
|
|
if ($ln eq 'rubyb') { |
471 |
|
|
my $class = join ' ', |
472 |
|
|
'descriptive', |
473 |
|
|
split /\s+/, $source->get_attribute_value |
474 |
|
|
('class', default => ''); |
475 |
|
|
$_->set_attribute (class => $class) if $class; |
476 |
|
|
} else { |
477 |
|
|
my $class = $source->get_attribute_value ('class', default => ''); |
478 |
|
|
$_->set_attribute (class => $class) if $class; |
479 |
|
|
} |
480 |
|
|
$apply_template_children->($child[0] |
481 |
|
|
=> $_->append_new_node (type => '#element', |
482 |
|
|
namespace_uri => $NS_XHTML1, |
483 |
|
|
local_name => 'rb')); |
484 |
|
|
$_->append_new_node (type => '#element', |
485 |
|
|
namespace_uri => $NS_XHTML1, |
486 |
|
|
local_name => 'rp') |
487 |
|
|
->append_text ('('); |
488 |
|
|
if ($child[1]) { |
489 |
|
|
$apply_template_children->($child[1] |
490 |
|
|
=> $_->append_new_node (type => '#element', |
491 |
|
|
namespace_uri => $NS_XHTML1, |
492 |
|
|
local_name => 'rt')); |
493 |
|
|
} else { |
494 |
|
|
$_->append_new_node (type => '#element', |
495 |
|
|
namespace_uri => $NS_XHTML1, |
496 |
|
|
local_name => 'rt'); |
497 |
|
|
} |
498 |
|
|
if ($child[2]) { |
499 |
|
|
$_->append_new_node (type => '#element', |
500 |
|
|
namespace_uri => $NS_XHTML1, |
501 |
|
|
local_name => 'rp') |
502 |
|
|
->append_text ('/'); |
503 |
|
|
$apply_template_children->($child[2] |
504 |
|
|
=> $_->append_new_node (type => '#element', |
505 |
|
|
namespace_uri => $NS_XHTML1, |
506 |
|
|
local_name => 'rt')); |
507 |
wakaba |
1.5 |
} |
508 |
wakaba |
1.6 |
$_->append_new_node (type => '#element', |
509 |
|
|
namespace_uri => $NS_XHTML1, |
510 |
|
|
local_name => 'rp') |
511 |
|
|
->append_text (')'); |
512 |
wakaba |
1.5 |
} |
513 |
wakaba |
1.6 |
} elsif ($ln eq 'abbr') { |
514 |
|
|
my (@b); |
515 |
|
|
for (@{$source->child_nodes}) { |
516 |
|
|
push @b, $_ if {qw/rb 1 rt 1/}->{$_->local_name}; |
517 |
wakaba |
1.5 |
} |
518 |
wakaba |
1.6 |
my $node = $result->append_new_node |
519 |
|
|
(type => '#element', |
520 |
|
|
namespace_uri => $NS_XHTML1, |
521 |
|
|
local_name => 'abbr'); |
522 |
|
|
$node->set_attribute (title => $b[1]->inner_text) if $b[1]; |
523 |
|
|
$apply_template_children->($b[0] => $node); |
524 |
|
|
} elsif ($ln eq 'q') { |
525 |
|
|
my $node = $result->append_new_node |
526 |
|
|
(type => '#element', |
527 |
|
|
namespace_uri => $NS_XHTML1, |
528 |
|
|
local_name => 'q'); |
529 |
|
|
## TODO: cite |
530 |
|
|
$apply_template_children->($source => $node); |
531 |
|
|
} elsif ($ln eq 'weak') { |
532 |
|
|
my $node = $result->append_new_node |
533 |
|
|
(type => '#element', |
534 |
|
|
namespace_uri => $NS_XHTML1, |
535 |
|
|
local_name => 'span'); |
536 |
|
|
$node->set_attribute (class => 'weak'); |
537 |
|
|
$apply_template_children->($source => $node); |
538 |
|
|
} elsif ({qw/section 1 bodytext 1/}->{$ln}) { |
539 |
|
|
my $node = $result->append_new_node |
540 |
|
|
(type => '#element', |
541 |
|
|
namespace_uri => $NS_XHTML1, |
542 |
|
|
local_name => 'div'); |
543 |
|
|
$node->set_attribute (class => $ln); |
544 |
|
|
local $opt{o}->{var}->{ws__section_depth} |
545 |
|
|
= $opt{o}->{var}->{ws__section_depth} + 1; |
546 |
|
|
$apply_template_children->($source => $node); |
547 |
|
|
} elsif ($ln eq 'anchor-end') { |
548 |
|
|
my $node = $result->append_new_node |
549 |
|
|
(type => '#element', |
550 |
|
|
namespace_uri => $NS_XHTML1, |
551 |
|
|
local_name => 'a'); |
552 |
|
|
$node->set_attribute (id => 'anchor-'.$source->get_attribute_value |
553 |
|
|
('anchor', default => '0', |
554 |
|
|
namespace_uri => $NS_SW09)); |
555 |
|
|
$node->append_text ($source->inner_text); |
556 |
|
|
} elsif ($ln eq 'anchor-internal') { |
557 |
|
|
my $node = $result->append_new_node |
558 |
|
|
(type => '#element', |
559 |
|
|
namespace_uri => $NS_XHTML1, |
560 |
|
|
local_name => 'a'); |
561 |
|
|
$node->set_attribute (href => '#anchor-'.$source->get_attribute_value |
562 |
|
|
('anchor', |
563 |
|
|
namespace_uri => $NS_SW09, default => '0')); |
564 |
|
|
$node->set_attribute (class => 'wiki-anchor'); |
565 |
|
|
$node->append_text ($source->inner_text); |
566 |
|
|
} elsif ($ln eq 'anchor-external') { |
567 |
|
|
local $opt{o}->{var}->{sw09__anchor_content} = sub { |
568 |
|
|
$apply_template_children->($source => shift); |
569 |
|
|
}; |
570 |
|
|
SuikaWiki::Plugin->module_package ('WikiLinking') |
571 |
|
|
->to_resource_in_html ( |
572 |
|
|
{ |
573 |
|
|
label => SuikaWiki::Plugin->module_package ('WikiResource') |
574 |
|
|
->get_text (name => |
575 |
|
|
'Link:SuikaWiki/0.9:toResource:SourceLabel', |
576 |
|
|
param => $opt{o}, |
577 |
|
|
wiki => $opt{o}->{wiki}), |
578 |
|
|
}, { |
579 |
|
|
resource_scheme => |
580 |
|
|
$source->get_attribute_value ('resScheme', |
581 |
|
|
namespace_uri => $NS_SW09, |
582 |
|
|
default => 'URI'), |
583 |
|
|
resource_parameter => |
584 |
|
|
$source->get_attribute_value ('resParameter', |
585 |
|
|
namespace_uri => $NS_SW09, |
586 |
|
|
default => ''), |
587 |
|
|
}, { |
588 |
|
|
o => $opt{o}, |
589 |
|
|
parent => $result, |
590 |
|
|
}); |
591 |
|
|
} elsif ($ln eq 'form') { |
592 |
|
|
my $ref = $source->get_attribute_value ('ref', default => 'form'); |
593 |
|
|
if ($ref eq 'form') { |
594 |
|
|
SuikaWiki::Plugin->module_package ('WikiFormCore') |
595 |
|
|
->make_content_form_in_html |
596 |
|
|
($result, |
597 |
|
|
$source->get_attribute_value |
598 |
|
|
('input', default => ''), |
599 |
|
|
option => $source->get_attribute_value |
600 |
|
|
('option'), |
601 |
|
|
name => $source->get_attribute_value ('id'), |
602 |
|
|
o => $opt{o}, |
603 |
|
|
wiki => $opt{o}->{wiki}, |
604 |
|
|
output => { |
605 |
|
|
page => $opt{page}, |
606 |
|
|
}); |
607 |
|
|
} elsif ($ref eq 'comment') { |
608 |
|
|
SuikaWiki::Plugin->module_package ('WikiFormCore') |
609 |
|
|
->make_content_form_in_html |
610 |
|
|
($result, |
611 |
|
|
$WIKIRESOURCE->get |
612 |
|
|
(name => 'SuikaWiki/0.9:form:comment:input', |
613 |
|
|
o => $opt{o}, wiki => $opt{o}->{wiki}), |
614 |
|
|
option => $WIKIRESOURCE->get |
615 |
|
|
(name => 'SuikaWiki/0.9:form:comment:option', |
616 |
|
|
o => $opt{o}, wiki => $opt{o}->{wiki}), |
617 |
|
|
name => $source->get_attribute_value ('id'), |
618 |
|
|
o => $opt{o}, |
619 |
|
|
wiki => $opt{o}->{wiki}, |
620 |
|
|
output => { |
621 |
|
|
page => $opt{page}, |
622 |
|
|
}); |
623 |
wakaba |
1.5 |
} else { |
624 |
wakaba |
1.6 |
## TODO: |
625 |
|
|
} |
626 |
|
|
} elsif ($ln eq 'dr') { |
627 |
|
|
$apply_template_children->($source => $result); |
628 |
|
|
} elsif ($ln eq 'document') { |
629 |
|
|
my $body; |
630 |
|
|
for (@{$source->child_nodes}) { |
631 |
|
|
$body = $_ and last if $_->local_name eq 'body'; |
632 |
wakaba |
1.5 |
} |
633 |
wakaba |
1.6 |
my $body_block = $result->append_new_node |
634 |
|
|
(type => '#element', |
635 |
|
|
namespace_uri => $NS_XHTML1, |
636 |
|
|
local_name => 'div'); |
637 |
|
|
$body_block->set_attribute (class => 'block SuikaWiki-0-9'); |
638 |
|
|
$apply_template_children->($body => $body_block); |
639 |
|
|
} else { |
640 |
|
|
my $node = $result->append_new_node |
641 |
|
|
(type => '#element', |
642 |
|
|
namespace_uri => $NS_XHTML1, |
643 |
|
|
local_name => 'span'); |
644 |
|
|
$node->set_attribute (class => 'warn'); |
645 |
|
|
for ($node->append_new_node |
646 |
|
|
(type => '#element', |
647 |
|
|
namespace_uri => $NS_XHTML1, |
648 |
|
|
local_name => 'ins') |
649 |
|
|
->append_new_node |
650 |
|
|
(type => '#element', |
651 |
|
|
namespace_uri => $NS_XHTML1, |
652 |
|
|
local_name => 'code')) { |
653 |
|
|
$_->set_attribute (class => 'XML element'); |
654 |
|
|
$_->append_text ("<".$source->namespace_uri.">:$ln"); |
655 |
wakaba |
1.4 |
} |
656 |
wakaba |
1.6 |
$apply_template_children->($source => $node); |
657 |
wakaba |
1.4 |
} |
658 |
|
|
}; |
659 |
wakaba |
1.6 |
|
660 |
|
|
$apply_template_children->($opt{source} => $opt{parent}); |
661 |
wakaba |
1.4 |
|
662 |
|
|
|
663 |
|
|
Function: |
664 |
|
|
@Name: xml_to_text |
665 |
|
|
@Main: |
666 |
|
|
my (undef, $src, $opt) = @_; |
667 |
|
|
|
668 |
|
|
|
669 |
|
|
my %is_block = ( |
670 |
|
|
qw/p 1 blockquote 1 pre 1 ul 1 ol 1 dl 1 section 1 h 1 |
671 |
|
|
bodytext 1 document 1 head 1 body 1 table 1 text 1 form 1 |
672 |
|
|
insert 1 delete 1/ |
673 |
|
|
); |
674 |
|
|
|
675 |
|
|
my %x2t; |
676 |
|
|
%x2t = ( |
677 |
|
|
anchor => sub { |
678 |
|
|
my $source = shift; |
679 |
|
|
my $result = '[[' |
680 |
|
|
. $x2t{'#inline'}->($source, no_newline => 1) |
681 |
|
|
. ']'; |
682 |
|
|
my $anchor = $source->get_attribute_value |
683 |
|
|
('anchor', |
684 |
|
|
namespace_uri => $NS_SW09, |
685 |
|
|
default => ''); |
686 |
|
|
if (length $anchor) { |
687 |
|
|
$result .= '>>'.(0+$anchor); |
688 |
|
|
} else { |
689 |
|
|
$anchor = $source->get_attribute_value |
690 |
|
|
('resScheme', |
691 |
|
|
namespace_uri => $NS_SW09); |
692 |
|
|
if ($anchor) { |
693 |
|
|
my $param = $source->get_attribute_value |
694 |
|
|
('resParameter', |
695 |
|
|
namespace_uri => $NS_SW09); |
696 |
|
|
if ($anchor eq 'URI' and $param =~ /^[0-9A-Za-z_+.%-]+:/) { |
697 |
|
|
$result .= '<' . $param . '>'; |
698 |
|
|
} else { |
699 |
|
|
$result .= '<' . $anchor . ':' . $param . '>'; |
700 |
|
|
} |
701 |
|
|
} |
702 |
|
|
} |
703 |
|
|
$result . ']'; |
704 |
|
|
}, |
705 |
|
|
li => sub { |
706 |
|
|
my $source = shift; |
707 |
|
|
my $result = ({qw/ul - ol =/}->{$opt->{o}->{var}->{sw09__list_type}} |
708 |
|
|
x $opt->{o}->{var}->{sw09__list_depth}) |
709 |
|
|
. ' ' . $x2t{'#flow'}->($source); |
710 |
|
|
$result; |
711 |
|
|
}, |
712 |
|
|
dt => sub { |
713 |
|
|
':' . $x2t{'#inline'}->(return, no_newline => 1) . ':'; |
714 |
|
|
}, |
715 |
|
|
h => sub { |
716 |
|
|
("*" x ($opt->{o}->{var}->{ws__section_depth} - 1)) |
717 |
|
|
. " " |
718 |
|
|
. $x2t{'#inline'}->(shift, no_newline => 1); |
719 |
|
|
}, |
720 |
|
|
'anchor-end' => sub { |
721 |
|
|
return shift->inner_text; |
722 |
|
|
}, |
723 |
|
|
'anchor-internal' => sub { |
724 |
|
|
return shift->inner_text; |
725 |
|
|
}, |
726 |
|
|
'anchor-external' => sub { |
727 |
|
|
return '<'.shift->inner_text.'>'; |
728 |
|
|
}, |
729 |
|
|
form => sub { |
730 |
|
|
my $source = shift; |
731 |
|
|
my $ref = $source->get_attribute_value ('ref', default => 'form'); |
732 |
|
|
my $result = '[[#'.$ref; |
733 |
|
|
my $name = $source->get_attribute_value ('id'); |
734 |
|
|
$name =~ s/([()\\])/\\$1/g; |
735 |
|
|
$result .= '(' . $name . ')' if $name; |
736 |
|
|
## General WikiForm |
737 |
|
|
if ($ref eq 'form') { |
738 |
|
|
$result .= ":'"; |
739 |
|
|
my $input = $source->get_attribute_value ('input', default => ''); |
740 |
|
|
$input =~ s/(['\\])/\\$1/g; |
741 |
|
|
$result .= $input . "':'"; |
742 |
|
|
my $template = $source->get_attribute_value ('template', default => ''); |
743 |
|
|
$template =~ s/(['\\])/\\$1/g; |
744 |
|
|
$result .= $template . "'"; |
745 |
|
|
my $option = $source->get_attribute_value ('option'); |
746 |
|
|
if ($option) { |
747 |
|
|
$option =~ s/(['\\])/\\$1/g; |
748 |
|
|
$result .= ":'" . $option . "'"; |
749 |
|
|
} |
750 |
|
|
## Specific WikiForm |
751 |
|
|
} else { |
752 |
|
|
my $param = $source->get_attribute_value ('parameter'); |
753 |
|
|
if ($param) { |
754 |
|
|
$result .= ':' . $param; |
755 |
|
|
} |
756 |
|
|
} |
757 |
|
|
$result .= ']]'; |
758 |
|
|
}, |
759 |
|
|
pre => sub { |
760 |
|
|
my $source = shift; |
761 |
|
|
my $result = '[PRE'; |
762 |
|
|
my $class = $source->get_attribute_value ('class'); |
763 |
|
|
if ($class) { |
764 |
|
|
$class =~ s/([\\()])/\\$1/g; |
765 |
|
|
$result .= '(' . $class . ')'; |
766 |
|
|
} |
767 |
|
|
$result .= "[\x0A" |
768 |
|
|
. $x2t{'#inline'}->($source); |
769 |
|
|
$result .= "\x0A" unless substr ($result, -1) eq "\x0A"; |
770 |
|
|
$result .= "]PRE]\x0A"; |
771 |
|
|
}, |
772 |
|
|
insert => sub { |
773 |
|
|
my $source = shift; |
774 |
|
|
my $result = '[INS'; |
775 |
|
|
my $class = $source->get_attribute_value ('class'); |
776 |
|
|
if ($class) { |
777 |
|
|
$class =~ s/([\\()])/\\$1/g; |
778 |
|
|
$result .= '(' . $class . ')'; |
779 |
|
|
} |
780 |
|
|
local $opt->{o}->{var}->{sw09__list_depth} = 0; |
781 |
|
|
$result .= "[\x0A" |
782 |
|
|
. $x2t{'#block'}->($source); |
783 |
|
|
$result .= "\x0A" unless substr ($result, -1) eq "\x0A"; |
784 |
|
|
$result .= "]INS]\x0A"; |
785 |
|
|
}, |
786 |
|
|
delete => sub { |
787 |
|
|
my $source = shift; |
788 |
|
|
my $result = '[DEL'; |
789 |
|
|
my $class = $source->get_attribute_value ('class'); |
790 |
|
|
if ($class) { |
791 |
|
|
$class =~ s/([\\()])/\\$1/g; |
792 |
|
|
$result .= '(' . $class . ')'; |
793 |
|
|
} |
794 |
|
|
local $opt->{o}->{var}->{sw09__list_depth} = 0; |
795 |
|
|
$result .= "[\x0A" |
796 |
|
|
. $x2t{'#block'}->($source); |
797 |
|
|
$result .= "\x0A" unless substr ($result, -1) eq "\x0A"; |
798 |
|
|
$result .= "]DEL]\x0A"; |
799 |
|
|
}, |
800 |
|
|
document => sub { |
801 |
|
|
my $source = shift; |
802 |
wakaba |
1.6 |
my $result = '#?' |
803 |
|
|
. $source->get_attribute_value |
804 |
|
|
('Name', namespace_uri => $NS_SW09, |
805 |
|
|
default => 'SuikaWiki') |
806 |
|
|
. '/' |
807 |
|
|
. $source->get_attribute_value |
808 |
|
|
('Version', namespace_uri => $NS_SW09, |
809 |
|
|
default => '0.9'); |
810 |
wakaba |
1.4 |
for (@{$source->child_nodes}) { |
811 |
|
|
$result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_) |
812 |
|
|
if $_->node_type eq '#element'; |
813 |
|
|
} |
814 |
|
|
$result; |
815 |
|
|
}, |
816 |
|
|
head => sub { |
817 |
|
|
my $source = shift; |
818 |
wakaba |
1.6 |
my $result = ''; |
819 |
wakaba |
1.4 |
for (@{$source->child_nodes}) { |
820 |
|
|
if ($_->node_type eq '#element' and |
821 |
|
|
$_->local_name eq 'parameter') { |
822 |
|
|
$result .= ' '.$x2t{parameter}->($_); |
823 |
|
|
} |
824 |
|
|
} |
825 |
|
|
$result . "\x0A"; |
826 |
|
|
}, |
827 |
|
|
parameter => sub { |
828 |
|
|
my $source = shift; |
829 |
|
|
my $result = $source->get_attribute_value ('name', default => '') |
830 |
|
|
. '="'; |
831 |
|
|
my @v; |
832 |
|
|
for (@{$source->child_nodes}) { |
833 |
|
|
push @v, $x2t{value}->($_) if $_->node_type eq '#element' and |
834 |
|
|
$_->local_name eq 'value'; |
835 |
|
|
} |
836 |
|
|
$result .= join ',', @v; |
837 |
|
|
$result . '"'; |
838 |
|
|
}, |
839 |
|
|
value => sub { |
840 |
|
|
my $value = $x2t{'#inline'}->(shift, no_newline => 1); |
841 |
|
|
$value =~ s/(["\\])/\\$1/g; |
842 |
|
|
$value =~ tr/\x0A\x0D/ /; |
843 |
|
|
$value; |
844 |
|
|
}, |
845 |
|
|
section => sub { |
846 |
|
|
local $opt->{o}->{var}->{ws__section_depth} |
847 |
|
|
= $opt->{o}->{var}->{ws__section_depth} + 1; |
848 |
|
|
$x2t{'#block'}->(shift); |
849 |
|
|
}, |
850 |
|
|
body => sub { |
851 |
|
|
local $opt->{o}->{var}->{ws__section_depth} = 1; |
852 |
|
|
$x2t{'#block'}->(shift); |
853 |
|
|
}, |
854 |
|
|
text => sub { |
855 |
|
|
my ($source, %opt) = @_; |
856 |
|
|
my $result .= ''; |
857 |
|
|
for (@{$source->child_nodes}) { |
858 |
|
|
if ($_->node_type eq '#text') { |
859 |
|
|
$result .= $_->inner_text; |
860 |
|
|
} elsif ($_->node_type eq '#element') { |
861 |
|
|
$result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_); |
862 |
|
|
} |
863 |
|
|
} |
864 |
|
|
$result; |
865 |
|
|
}, |
866 |
|
|
dr => sub { |
867 |
|
|
my $result = $x2t{'#list'}->(shift); |
868 |
|
|
if ($result) { |
869 |
|
|
$result . "\x0A"; |
870 |
|
|
} else { |
871 |
|
|
"::\x0A"; |
872 |
|
|
} |
873 |
|
|
}, |
874 |
|
|
dt => sub { |
875 |
|
|
':' . $x2t{'#inline'}->(shift, no_newline => 1) . ':'; |
876 |
|
|
}, |
877 |
|
|
dd => sub { |
878 |
|
|
$x2t{'#inline'}->(shift); |
879 |
|
|
}, |
880 |
|
|
tr => sub { |
881 |
|
|
my $result = $x2t{'#list'}->(shift); |
882 |
|
|
if ($result) { |
883 |
|
|
substr ($result, 1) . "\x0A"; |
884 |
|
|
} else { |
885 |
|
|
"',\x0A"; |
886 |
|
|
} |
887 |
|
|
}, |
888 |
|
|
td => sub { |
889 |
|
|
my $source = shift; |
890 |
|
|
my $result = $x2t{'#inline'}->($source, no_newline => 1); |
891 |
|
|
if ($result =~ /[,"\\]/ or $result =~ /==/) { |
892 |
|
|
$result =~ s/(["\\])/\\$1/g; |
893 |
|
|
$result = '"' . $result . '"'; |
894 |
|
|
} |
895 |
|
|
my $colspan = $source->get_attribute_value ('colspan', default => 1); |
896 |
|
|
$result .= ("\t,==" x ($colspan - 1)) if $colspan > 1; |
897 |
|
|
"\t," . $result; |
898 |
|
|
}, |
899 |
|
|
em => sub { |
900 |
|
|
"''" . $x2t{'#inline'}->($_, no_newline => 1) . "''"; |
901 |
|
|
}, |
902 |
|
|
strong => => sub { |
903 |
|
|
"'''" . $x2t{'#inline'}->($_, no_newline => 1) . "'''"; |
904 |
|
|
}, |
905 |
|
|
rb => sub { |
906 |
|
|
$x2t{'#inline'}->(shift, no_newline => 1); |
907 |
|
|
}, |
908 |
|
|
rt => sub { |
909 |
|
|
'] [' . $x2t{'#inline'}->(shift, no_newline => 1); |
910 |
|
|
}, |
911 |
|
|
replace => sub { |
912 |
|
|
'__&&' . shift->get_attribute_value ('by', default => '') . '&&__'; |
913 |
|
|
}, |
914 |
|
|
bodytext => sub { |
915 |
|
|
my ($source, %opt) = @_; |
916 |
|
|
local $opt->{o}->{var}->{sw09__bq_depth} |
917 |
|
|
= $opt->{o}->{var}->{sw09__bq_depth} + 1; |
918 |
|
|
my @result; |
919 |
|
|
for (@{$source->child_nodes}) { |
920 |
|
|
if ($_->node_type eq '#element') { |
921 |
|
|
my $ln = $_->local_name; |
922 |
|
|
push @result, [($x2t{$ln} or $x2t{'#undef'})->($_), |
923 |
|
|
$ln]; |
924 |
|
|
} |
925 |
|
|
} |
926 |
|
|
my $result = ''; |
927 |
|
|
my $prev = ''; |
928 |
|
|
for (@result) { |
929 |
|
|
my $s = $_->[0]; |
930 |
|
|
if ($_->[1] eq 'p') { |
931 |
|
|
$result .= "\x0A" if length $result and |
932 |
|
|
substr ($result, -1) ne "\x0A"; |
933 |
|
|
$result .= ('>' x $opt->{o}->{var}->{sw09__bq_depth}) . ' '; |
934 |
|
|
} elsif ($_->[1] eq 'form' or $_->[1] eq 'replace') { |
935 |
|
|
$result .= "\x0A" if length $result and |
936 |
|
|
substr ($result, -1) ne "\x0A"; |
937 |
|
|
$result .= ('>' x $opt->{o}->{var}->{sw09__bq_depth})."\x0A"; |
938 |
|
|
} elsif ($_->[1] eq 'blockquote' or $_->[1] eq 'text') { |
939 |
|
|
$result .= "\x0A" if length $result and |
940 |
|
|
substr ($result, -1) ne "\x0A"; |
941 |
|
|
} else { |
942 |
|
|
unless ($prev eq 'text') { |
943 |
|
|
$result .= "\x0A" if length $result and |
944 |
|
|
substr ($result, -1) ne "\x0A"; |
945 |
|
|
} |
946 |
|
|
$result .= ('>' x $opt->{o}->{var}->{sw09__bq_depth})."\x0A"; |
947 |
|
|
} |
948 |
|
|
$result .= $s; |
949 |
|
|
$prev = $_->[1]; |
950 |
|
|
} |
951 |
|
|
$result; |
952 |
|
|
}, |
953 |
wakaba |
1.6 |
## Note: This element will be interpreted as a paragraph |
954 |
|
|
## unless format is SuikaWikiImage/0.9. |
955 |
|
|
image => sub { |
956 |
|
|
my ($source, %opt) = @_; |
957 |
|
|
return "\x0A__IMAGE__\x0A" . $source->inner_text . "\x0A"; |
958 |
|
|
}, |
959 |
wakaba |
1.4 |
'#block' => sub { |
960 |
|
|
my ($source, %opt) = @_; |
961 |
|
|
my @result; |
962 |
|
|
for (@{$source->child_nodes}) { |
963 |
|
|
if ($_->node_type eq '#element') { |
964 |
|
|
my $ln = $_->local_name; |
965 |
|
|
push @result, [($x2t{$ln} or $x2t{'#undef'})->($_), |
966 |
|
|
$ln]; |
967 |
|
|
} |
968 |
|
|
} |
969 |
|
|
my $result = ''; |
970 |
|
|
my $prev = ''; |
971 |
|
|
for (@result) { |
972 |
|
|
my $s = $_->[0]; |
973 |
|
|
if ($_->[1] eq 'form') { |
974 |
|
|
$result .= "\x0A" if length $result and |
975 |
|
|
substr ($result, -1) ne "\x0A"; |
976 |
|
|
$result .= "\x0A"; |
977 |
|
|
} elsif ($_->[1] eq 'replace') { |
978 |
|
|
$result .= "\x0A" if length $result and |
979 |
|
|
substr ($result, -1) ne "\x0A"; |
980 |
|
|
} elsif ($_->[1] eq 'text') { |
981 |
|
|
$result .= "\x0A" if length $result and |
982 |
|
|
substr ($result, -1) ne "\x0A"; |
983 |
|
|
$result .= "\x0A" if $prev eq 'p'; |
984 |
|
|
} else { |
985 |
|
|
if ($prev ne 'text' and $prev ne 'replace') { |
986 |
|
|
$result .= "\x0A" if length $result and |
987 |
|
|
substr ($result, -1) ne "\x0A"; |
988 |
|
|
$result .= "\x0A"; |
989 |
|
|
} |
990 |
|
|
} |
991 |
|
|
$result .= $s; |
992 |
|
|
$prev = $_->[1]; |
993 |
|
|
} |
994 |
|
|
$result; |
995 |
|
|
}, |
996 |
|
|
'#flow' => sub { |
997 |
|
|
my ($source, %opt) = @_; |
998 |
|
|
my @result; |
999 |
|
|
for (@{$source->child_nodes}) { |
1000 |
|
|
if ($_->node_type eq '#element') { |
1001 |
|
|
my $ln = $_->local_name; |
1002 |
|
|
if ($is_block{$ln}) { |
1003 |
|
|
push @result, [($x2t{$ln} or $x2t{'#undef'})->($_), |
1004 |
|
|
$ln]; |
1005 |
|
|
} else { |
1006 |
|
|
if (@result and ($result[$#result]->[1] eq '#inline')) { |
1007 |
|
|
$result[$#result]->[0] |
1008 |
|
|
.= ($x2t{$ln} or $x2t{'#undef'})->($_); |
1009 |
|
|
} else { |
1010 |
|
|
push @result, [($x2t{$ln} or $x2t{'#undef'})->($_), |
1011 |
|
|
'#inline']; |
1012 |
|
|
} |
1013 |
|
|
} |
1014 |
|
|
} elsif ($_->node_type eq '#text') { |
1015 |
|
|
if (@result and ($result[$#result]->[1] eq '#inline')) { |
1016 |
|
|
$result[$#result]->[0] .= $_->inner_text; |
1017 |
|
|
} else { |
1018 |
|
|
push @result, [$_->inner_text, '#inline']; |
1019 |
|
|
} |
1020 |
|
|
} |
1021 |
|
|
} |
1022 |
|
|
my $result = ''; |
1023 |
|
|
my $prev = ''; |
1024 |
|
|
for (@result) { |
1025 |
|
|
my $s = $_->[0]; |
1026 |
|
|
if ($_->[1] eq '#inline') { |
1027 |
|
|
if ($prev ne 'text' and $prev ne 'form' and $prev ne 'replace') { |
1028 |
|
|
$result .= "\x0A" if length $result and |
1029 |
|
|
substr ($result, -1) ne "\x0A"; |
1030 |
|
|
} |
1031 |
|
|
$s =~ s/\x0D\x0A/\x0A/g; |
1032 |
|
|
$s =~ s/\x0D/\x0A/g; |
1033 |
|
|
$s =~ s/\x0A\x0A+/\x0A/g; |
1034 |
|
|
$s =~ s/\x0A/\x20/g if $opt{no_newline}; |
1035 |
|
|
} elsif ($_->[1] eq 'form' or $_->[1] eq 'replace') { |
1036 |
|
|
if ($prev ne '#inline') { |
1037 |
|
|
$result .= "\x0A" if length $result and |
1038 |
|
|
substr ($result, -1) ne "\x0A"; |
1039 |
|
|
} |
1040 |
|
|
} elsif ($_->[1] eq 'text') { |
1041 |
|
|
$result .= "\x0A" if length $result and |
1042 |
|
|
substr ($result, -1) ne "\x0A"; |
1043 |
|
|
} else { |
1044 |
|
|
unless ($prev eq 'text') { |
1045 |
|
|
$result .= "\x0A" if length $result and |
1046 |
|
|
substr ($result, -1) ne "\x0A"; |
1047 |
|
|
} |
1048 |
|
|
} |
1049 |
|
|
$result .= $s; |
1050 |
|
|
$prev = $_->[1]; |
1051 |
|
|
} |
1052 |
|
|
$result; |
1053 |
|
|
}, |
1054 |
|
|
'#inline' => sub { |
1055 |
|
|
my ($source, %opt) = @_; |
1056 |
|
|
my $result .= ''; |
1057 |
|
|
for (@{$source->child_nodes}) { |
1058 |
|
|
if ($_->node_type eq '#text') { |
1059 |
|
|
$result .= $_->inner_text; |
1060 |
|
|
} elsif ($_->node_type eq '#element') { |
1061 |
|
|
$result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_); |
1062 |
|
|
} |
1063 |
|
|
} |
1064 |
|
|
$result =~ s/\x0D\x0A/\x0A/g; |
1065 |
|
|
$result =~ s/\x0D/\x0A/g; |
1066 |
|
|
$result =~ s/\x0A\x0A+/\x0A/g; |
1067 |
|
|
$result =~ s/\x0A/\x20/g if $opt{no_newline}; |
1068 |
|
|
$result; |
1069 |
|
|
}, |
1070 |
|
|
'#list' => sub { |
1071 |
|
|
my ($source, %opt) = @_; |
1072 |
|
|
my $result .= ''; |
1073 |
|
|
for (@{$source->child_nodes}) { |
1074 |
|
|
if ($_->node_type eq '#element') { |
1075 |
|
|
$result .= ($x2t{$_->local_name} or $x2t{'#undef'})->($_); |
1076 |
|
|
} |
1077 |
|
|
} |
1078 |
|
|
$result; |
1079 |
|
|
}, |
1080 |
|
|
'#undef' => sub { |
1081 |
|
|
my $source = shift; |
1082 |
|
|
## TODO: |
1083 |
|
|
"<".$source->namespace_uri.">:".$source->local_name |
1084 |
|
|
. $x2t{'#inline'}->($source); |
1085 |
|
|
}, |
1086 |
|
|
); |
1087 |
|
|
for (qw/blockquote dl tbody table/) { |
1088 |
|
|
$x2t{$_} = sub { $x2t{'#list'}->(shift) }; |
1089 |
|
|
} |
1090 |
|
|
for (qw/p dd/) { |
1091 |
|
|
$x2t{$_} = sub { $x2t{'#flow'}->(shift) }; |
1092 |
|
|
} |
1093 |
|
|
for my $type (qw/ul ol/) { |
1094 |
|
|
$x2t{$type} = sub { |
1095 |
|
|
my $source = shift; |
1096 |
|
|
local $opt->{o}->{var}->{sw09__list_type} = $type; |
1097 |
|
|
local $opt->{o}->{var}->{sw09__list_depth} |
1098 |
|
|
= $opt->{o}->{var}->{sw09__list_depth} + 1; |
1099 |
|
|
my @result; |
1100 |
|
|
for (@{$source->child_nodes}) { |
1101 |
|
|
push @result, $x2t{$_->local_name}->($_) |
1102 |
|
|
if $_->node_type eq '#element'; |
1103 |
|
|
} |
1104 |
|
|
my $result = ''; |
1105 |
|
|
for (@result) { |
1106 |
|
|
$result .= "\x0A" unless substr ($result, -1) eq "\x0A"; |
1107 |
|
|
$result .= $_; |
1108 |
|
|
} |
1109 |
|
|
substr ($result, 1); |
1110 |
|
|
}; |
1111 |
|
|
} |
1112 |
|
|
for my $type (qw/code samp var dfn kbd sub sup weak q ruby rubyb |
1113 |
|
|
abbr ins del/) { |
1114 |
|
|
$x2t{$type} = sub { |
1115 |
|
|
my $source = shift; |
1116 |
|
|
my $result = '['.uc $type; |
1117 |
|
|
my $class = $source->get_attribute_value ('class', default => ''); |
1118 |
|
|
if ($class) { |
1119 |
|
|
$class =~ s/([()\\])/\\$1/g; |
1120 |
|
|
$result .= '(' . $class . ')'; |
1121 |
|
|
} |
1122 |
|
|
$result .= '[' |
1123 |
|
|
. $x2t{'#inline'}->($source, no_newline => 1) |
1124 |
|
|
. ']'; |
1125 |
|
|
my $anchor = $source->get_attribute_value |
1126 |
|
|
('anchor', |
1127 |
|
|
namespace_uri => $NS_SW09, |
1128 |
|
|
default => ''); |
1129 |
|
|
if (length $anchor) { |
1130 |
|
|
$result .= '>>'.(0+$anchor); |
1131 |
|
|
} else { |
1132 |
|
|
$anchor = $source->get_attribute_value |
1133 |
|
|
('resScheme', |
1134 |
|
|
namespace_uri => $NS_SW09); |
1135 |
|
|
if ($anchor) { |
1136 |
|
|
my $param = $source->get_attribute_value |
1137 |
|
|
('resParameter', |
1138 |
|
|
namespace_uri => $NS_SW09); |
1139 |
|
|
if ($anchor eq 'URI' and $param =~ /^[0-9A-Za-z_+.%-]+:/) { |
1140 |
|
|
$result .= '<' . $param . '>'; |
1141 |
|
|
} else { |
1142 |
|
|
$result .= '<' . $anchor . ':' . $param . '>'; |
1143 |
|
|
} |
1144 |
|
|
} |
1145 |
|
|
} |
1146 |
|
|
$result .= ']'; |
1147 |
|
|
$result; |
1148 |
|
|
}; |
1149 |
|
|
} |
1150 |
|
|
|
1151 |
|
|
$x2t{'#list'}->($src); |
1152 |
|
|
|
1153 |
|
|
Function: |
1154 |
|
|
@Name: get_nth_element |
1155 |
|
|
@Main: |
1156 |
|
|
my (undef, $node, $ns => $ln, $n) = @_; |
1157 |
|
|
return $n if $n < 1; |
1158 |
|
|
if ($node->node_type eq '#element' and |
1159 |
|
|
$node->namespace_uri eq $ns and |
1160 |
|
|
$node->local_name eq $ln) { |
1161 |
|
|
return $node unless --$n; |
1162 |
|
|
} |
1163 |
|
|
for (@{$node->child_nodes}) { |
1164 |
|
|
if ($_->node_type eq '#element') { |
1165 |
|
|
if ($_->namespace_uri eq $ns and |
1166 |
|
|
$_->local_name eq $ln) { |
1167 |
|
|
return $_ unless --$n; |
1168 |
|
|
} else { |
1169 |
|
|
$n = __FUNCPACK__->get_nth_element ($_, $ns => $ln, $n); |
1170 |
|
|
return $n if ref $n; |
1171 |
|
|
} |
1172 |
|
|
} elsif ($_->node_type eq '#fragment' or $_->node_type eq '#document') { |
1173 |
|
|
$n = __FUNCPACK__->get_nth_element ($_, $ns => $ln, $n); |
1174 |
|
|
return $n if ref $n; |
1175 |
|
|
} |
1176 |
|
|
} |
1177 |
|
|
return $n; |
1178 |
|
|
|
1179 |
|
|
Function: |
1180 |
|
|
@Name: get_element_by_id |
1181 |
|
|
@Main: |
1182 |
|
|
my (undef, $node, $id) = @_; |
1183 |
|
|
return $node if $node->node_type eq '#element' |
1184 |
|
|
and $node->get_attribute_value ('id', default_value => '') |
1185 |
|
|
eq $id; |
1186 |
|
|
for (@{$node->child_nodes}) { |
1187 |
|
|
if ({'#element'=>1, '#fragment'=>1, '#document'=>1}->{$_->node_type}) { |
1188 |
|
|
my $r = __FUNCPACK__->get_element_by_id ($_, $id); |
1189 |
|
|
return $r if $r; |
1190 |
|
|
} |
1191 |
|
|
} |
1192 |
wakaba |
1.1 |
|
1193 |
|
|
Function: |
1194 |
|
|
@Name: text_to_xml |
1195 |
|
|
@Description: |
1196 |
|
|
@@@: |
1197 |
|
|
Converting SuikaWiki/0.9 text format to XML representation |
1198 |
|
|
@@lang: en |
1199 |
|
|
@Main: |
1200 |
|
|
my (undef, $source, $opt) = @_; |
1201 |
|
|
$source =~ s/\x0D\x0A/\x0A/g; |
1202 |
|
|
$source =~ tr/\x0D/\x0A/; |
1203 |
|
|
$source .= "\x0A"; |
1204 |
|
|
my $root = $opt->{-parent} |
1205 |
|
|
->append_new_node (type => '#element', |
1206 |
|
|
namespace_uri => $NS_SW09, |
1207 |
|
|
local_name => 'document'); |
1208 |
|
|
my $head = $root->append_new_node (type => '#element', |
1209 |
|
|
namespace_uri => $NS_XHTML2, |
1210 |
|
|
local_name => 'head'); |
1211 |
wakaba |
1.6 |
$root->append_text ("\x0A"); |
1212 |
|
|
my $body = $root->append_new_node (type => '#element', |
1213 |
|
|
namespace_uri => $NS_XHTML2, |
1214 |
|
|
local_name => 'body'); |
1215 |
|
|
$root->append_text ("\x0A"); |
1216 |
|
|
|
1217 |
|
|
if ($source =~ s#^\#\?(SuikaWiki(?:Image)?)/0\.9\b((?>.*))\s*##) { |
1218 |
|
|
my $type = $1; |
1219 |
|
|
my $param = $2; |
1220 |
|
|
$root->set_attribute (Name => $type, namespace_uri => $NS_SW09); |
1221 |
|
|
$root->set_attribute (Version => '0.9', namespace_uri => $NS_SW09); |
1222 |
wakaba |
1.1 |
while ($param =~ /\G\s+([a-z-]+)="((?>[^"\\]*)(?>(?>[^"\\]+|\\.)*))"/g) { |
1223 |
|
|
my ($name, $value) = ($1, $2); |
1224 |
|
|
$value =~ s/\\(.)/$1/g; |
1225 |
|
|
for ($head->append_new_node (type => '#element', |
1226 |
|
|
namespace_uri => $NS_SW09, |
1227 |
wakaba |
1.4 |
local_name => 'parameter')) { |
1228 |
wakaba |
1.1 |
$_->set_attribute (name => $name); |
1229 |
|
|
for my $value (split /,/, $value) { |
1230 |
|
|
$_->append_new_node (type => '#element', |
1231 |
|
|
namespace_uri => $NS_SW09, |
1232 |
|
|
local_name => 'value') |
1233 |
|
|
->append_text ($value); |
1234 |
|
|
} |
1235 |
|
|
} |
1236 |
|
|
$head->append_text ("\x0A"); |
1237 |
|
|
} |
1238 |
wakaba |
1.6 |
|
1239 |
|
|
if ($type eq 'SuikaWikiImage') { |
1240 |
|
|
$source =~ s/\x0A__IMAGE__\x0A(.*)$//s; |
1241 |
|
|
if (my $image = $1) { |
1242 |
|
|
$image =~ s/^\s+//; |
1243 |
|
|
$image =~ s/\s+$//; |
1244 |
|
|
$root->append_new_node |
1245 |
|
|
(type => '#element', |
1246 |
|
|
namespace_uri => $NS_SW09, |
1247 |
|
|
local_name => 'image') |
1248 |
|
|
->append_text ($image); |
1249 |
|
|
$root->append_text ("\x0A"); |
1250 |
|
|
} |
1251 |
|
|
} |
1252 |
wakaba |
1.1 |
} else { |
1253 |
wakaba |
1.6 |
$root->set_attribute (Name => 'SuikaWiki', namespace_uri => $NS_SW09); |
1254 |
|
|
$root->set_attribute (Version => '0.9', namespace_uri => $NS_SW09); |
1255 |
wakaba |
1.1 |
## TODO: warn |
1256 |
|
|
} |
1257 |
|
|
|
1258 |
wakaba |
1.4 |
__FUNCPACK__->block_text_to_xml (\$source => $body, opt => $opt); |
1259 |
wakaba |
1.1 |
|
1260 |
|
|
Function: |
1261 |
|
|
@Name:block_text_to_xml |
1262 |
|
|
@Description: |
1263 |
|
|
@@@: |
1264 |
|
|
SuikaWiki/0.9 text format to XML representation convertion - block |
1265 |
|
|
level elements |
1266 |
|
|
@@lang:en |
1267 |
|
|
@Main: |
1268 |
|
|
my (undef, $source, $current, %opt) = @_; |
1269 |
wakaba |
1.4 |
my %depth = %{$opt{depth} || {}}; |
1270 |
wakaba |
1.1 |
my $back_to_section = sub { |
1271 |
|
|
my $cur_type = $current->local_name; |
1272 |
|
|
while (not ( |
1273 |
|
|
$cur_type eq 'section' |
1274 |
|
|
or $cur_type eq 'body' |
1275 |
|
|
or $cur_type eq 'bodytext' |
1276 |
wakaba |
1.4 |
or $cur_type eq 'insert' |
1277 |
|
|
or $cur_type eq 'delete' |
1278 |
wakaba |
1.1 |
) |
1279 |
|
|
) { |
1280 |
|
|
$current = $current->parent_node; |
1281 |
|
|
$cur_type = $current->local_name; |
1282 |
|
|
} |
1283 |
|
|
delete $depth{list}; |
1284 |
|
|
}; |
1285 |
|
|
my $back_to_real_section = sub { |
1286 |
|
|
my $cur_type = $current->local_name; |
1287 |
|
|
while (not ( |
1288 |
|
|
$cur_type eq 'section' |
1289 |
|
|
or $cur_type eq 'body' |
1290 |
wakaba |
1.4 |
or $cur_type eq 'insert' |
1291 |
|
|
or $cur_type eq 'delete' |
1292 |
wakaba |
1.1 |
) |
1293 |
|
|
) { |
1294 |
|
|
$current = $current->parent_node; |
1295 |
|
|
$cur_type = $current->local_name; |
1296 |
|
|
} |
1297 |
|
|
delete $depth{bq}; |
1298 |
|
|
delete $depth{list}; |
1299 |
|
|
}; |
1300 |
|
|
while ($$source =~ /\G([^\x0A]*)\x0A/gc) { |
1301 |
|
|
my $line = $1; |
1302 |
|
|
if ($line eq '') { |
1303 |
|
|
$back_to_real_section->(); |
1304 |
|
|
} elsif ($line =~ s/^([-=]+)\s*//) { |
1305 |
|
|
my $list_type = substr ($1, -1) eq '-' ? 'ul' : 'ol'; |
1306 |
|
|
my $depth = length $1; |
1307 |
|
|
my $parent_type = $current->parent_node->local_name; |
1308 |
|
|
## Parent node is list element |
1309 |
|
|
if ($parent_type eq 'ul' or $parent_type eq 'ol') { |
1310 |
|
|
if ($depth{list} == $depth) { |
1311 |
|
|
if ($parent_type eq $list_type) { |
1312 |
|
|
$current = $current->parent_node; |
1313 |
|
|
} else { |
1314 |
|
|
$current = $current->parent_node |
1315 |
|
|
->parent_node |
1316 |
|
|
->append_new_node |
1317 |
|
|
(type => '#element', |
1318 |
|
|
namespace_uri => $NS_XHTML2, |
1319 |
|
|
local_name => $list_type); |
1320 |
|
|
} |
1321 |
|
|
} elsif ($depth < $depth{list}) { |
1322 |
|
|
for ($depth+1..$depth{list}) { |
1323 |
|
|
$current = $current->parent_node->parent_node; |
1324 |
|
|
} |
1325 |
|
|
$current = $current->parent_node; |
1326 |
|
|
if ($current->local_name ne $list_type) { |
1327 |
|
|
$current = $current->parent_node |
1328 |
|
|
->append_new_node |
1329 |
|
|
(type => '#element', |
1330 |
|
|
namespace_uri => $NS_XHTML2, |
1331 |
|
|
local_name => $list_type); |
1332 |
|
|
} |
1333 |
|
|
$depth{list} = $depth; |
1334 |
|
|
} else { # $depth{list} < $depth |
1335 |
|
|
$current = $current->append_new_node |
1336 |
|
|
(type => '#element', |
1337 |
|
|
namespace_uri => $NS_XHTML2, |
1338 |
|
|
local_name => $list_type); |
1339 |
|
|
$depth{list}++; |
1340 |
|
|
} |
1341 |
|
|
## Parent node is non-list element |
1342 |
|
|
} else { |
1343 |
|
|
$current = $current->append_new_node (type => '#element', |
1344 |
|
|
namespace_uri => $NS_XHTML2, |
1345 |
|
|
local_name => $list_type); |
1346 |
|
|
$depth{list} = 1; |
1347 |
|
|
} |
1348 |
|
|
$current->append_text ("\x0A".(" " x $depth{list})); |
1349 |
|
|
$current = $current->append_new_node (type => '#element', |
1350 |
|
|
namespace_uri => $NS_XHTML2, |
1351 |
|
|
local_name => 'li'); |
1352 |
wakaba |
1.4 |
__FUNCPACK__->inline_text_to_xml (\$line => $current, %opt); |
1353 |
wakaba |
1.1 |
} elsif ($line =~ s/^(\*+)\s*//) { |
1354 |
|
|
my $depth = length $1; |
1355 |
|
|
$back_to_real_section->(); |
1356 |
|
|
if ($depth <= $depth{section}) { |
1357 |
|
|
for ($depth..$depth{section}) { |
1358 |
|
|
$back_to_real_section->(); |
1359 |
|
|
$current = $current->parent_node; |
1360 |
|
|
} |
1361 |
|
|
$depth{section} = $depth; |
1362 |
|
|
} else { # $depth{section} < $depth |
1363 |
|
|
for ($depth{section}+2..$depth) { |
1364 |
|
|
$current = $current->append_new_node |
1365 |
|
|
(type => '#element', |
1366 |
|
|
namespace_uri => $NS_XHTML2, |
1367 |
|
|
local_name => 'section'); |
1368 |
|
|
} |
1369 |
|
|
$depth{section} = $depth; |
1370 |
|
|
} |
1371 |
|
|
$current = $current->append_new_node |
1372 |
|
|
(type => '#element', |
1373 |
|
|
namespace_uri => $NS_XHTML2, |
1374 |
|
|
local_name => 'section'); |
1375 |
|
|
__FUNCPACK__->inline_text_to_xml (\$line => |
1376 |
|
|
$current->append_new_node (type => '#element', |
1377 |
|
|
namespace_uri => $NS_XHTML2, |
1378 |
wakaba |
1.4 |
local_name => 'h'), %opt, |
1379 |
wakaba |
1.1 |
); |
1380 |
|
|
} elsif ($line =~ s/^(?!>>[0-9])(>+)\s*//) { |
1381 |
|
|
my $depth = length $1; |
1382 |
|
|
if ($depth <= $depth{bq}) { |
1383 |
|
|
for ($depth+1..$depth{bq}) { |
1384 |
|
|
$back_to_section->(); |
1385 |
|
|
$current = $current->parent_node->parent_node; |
1386 |
|
|
} |
1387 |
|
|
$back_to_section->(); |
1388 |
|
|
$current->append_text ("\x0A"); |
1389 |
|
|
$depth{bq} = $depth; |
1390 |
|
|
} else { # $depth{bq} < $depth |
1391 |
|
|
$back_to_section->(); |
1392 |
|
|
for ($depth{bq}+1..$depth) { |
1393 |
|
|
$current = $current->append_new_node |
1394 |
|
|
(type => '#element', |
1395 |
|
|
namespace_uri => $NS_XHTML2, |
1396 |
|
|
local_name => 'blockquote') |
1397 |
|
|
->append_new_node |
1398 |
|
|
(type => '#element', |
1399 |
|
|
namespace_uri => $NS_HTML3, |
1400 |
|
|
local_name => 'bodytext'); |
1401 |
|
|
$current->append_text ("\x0A"); |
1402 |
|
|
} |
1403 |
|
|
$depth{bq} = $depth; |
1404 |
|
|
} |
1405 |
|
|
if (length $line) { |
1406 |
|
|
$current = $current->append_new_node |
1407 |
|
|
(type => '#element', |
1408 |
|
|
namespace_uri => $NS_XHTML2, |
1409 |
|
|
local_name => 'p'); |
1410 |
wakaba |
1.4 |
__FUNCPACK__->inline_text_to_xml (\$line => $current, %opt); |
1411 |
wakaba |
1.1 |
} |
1412 |
|
|
} elsif ($line =~ s/^(?>:\s*)([^:]+?)\s*:\s*//) { |
1413 |
|
|
my $parent_type = $current->local_name; |
1414 |
|
|
if ($parent_type eq 'dd') { |
1415 |
|
|
$current = $current->parent_node->parent_node; |
1416 |
|
|
$current->append_text ("\x0A"); |
1417 |
|
|
} else { #if ($parent_type ne 'dl') { |
1418 |
|
|
$current = $current->append_new_node (type => '#element', |
1419 |
|
|
namespace_uri => $NS_XHTML2, |
1420 |
|
|
local_name => 'dl'); |
1421 |
|
|
} |
1422 |
|
|
$current = $current->append_new_node |
1423 |
|
|
(type => '#element', |
1424 |
|
|
namespace_uri => $NS_SW09, |
1425 |
|
|
local_name => 'dr'); |
1426 |
|
|
__FUNCPACK__->inline_text_to_xml (\"$1" => |
1427 |
|
|
$current->append_new_node (type => '#element', |
1428 |
|
|
namespace_uri => $NS_XHTML2, |
1429 |
wakaba |
1.4 |
local_name => 'dt'), %opt, |
1430 |
wakaba |
1.1 |
); |
1431 |
|
|
$current->append_text ("\x0A"); |
1432 |
|
|
$current = $current->append_new_node (type => '#element', |
1433 |
|
|
namespace_uri => $NS_XHTML2, |
1434 |
|
|
local_name => 'dd'); |
1435 |
wakaba |
1.4 |
__FUNCPACK__->inline_text_to_xml (\$line => $current, %opt); |
1436 |
wakaba |
1.1 |
} elsif ($line =~ /^\[(INS|DEL)(\([^()\\]*\))?\[\s*$/) { |
1437 |
|
|
$current->append_text ("\x0A"); |
1438 |
wakaba |
1.4 |
my $mod = $current->append_new_node |
1439 |
|
|
(type => '#element', |
1440 |
|
|
namespace_uri => $NS_SW09, |
1441 |
|
|
local_name => {qw/INS insert DEL delete/}->{$1}); |
1442 |
wakaba |
1.1 |
$mod->set_attribute (class => $2) if $2; |
1443 |
wakaba |
1.4 |
__FUNCPACK__->block_text_to_xml ($source => $mod, %opt, |
1444 |
|
|
'return_by_'.$1 => 1, |
1445 |
|
|
depth => \%depth); |
1446 |
wakaba |
1.1 |
} elsif ($line =~ /^\](INS|DEL)\]\s*$/) { |
1447 |
|
|
if ($opt{'return_by_'.$1}) { |
1448 |
|
|
return; |
1449 |
|
|
} else { |
1450 |
|
|
## TODO: warn |
1451 |
|
|
} |
1452 |
|
|
} elsif ($line =~ /^\[PRE(\([^()\\]*\))?\[\s*$/) { |
1453 |
|
|
$current->append_text ("\x0A"); |
1454 |
|
|
my $pre = $current->append_new_node (type => '#element', |
1455 |
|
|
namespace_uri => $NS_XHTML1, |
1456 |
|
|
local_name => 'pre'); |
1457 |
|
|
$pre->set_attribute (class => $1) if $1; |
1458 |
|
|
$pre->set_attribute (space => 'preserve', namespace_uri => NS_xml_URI); |
1459 |
|
|
my $f = 1; |
1460 |
|
|
while ($$source =~ /\G([^\x0A]*)\x0A/gc) { |
1461 |
|
|
my $line = $1; |
1462 |
|
|
if ($line =~ /^\]PRE\]\s*$/) { |
1463 |
|
|
undef $pre; |
1464 |
|
|
last; |
1465 |
|
|
} else { |
1466 |
|
|
$f ? undef $f : $pre->append_text ("\x0A"); |
1467 |
wakaba |
1.4 |
__FUNCPACK__->inline_text_to_xml (\$line => $pre, %opt); |
1468 |
wakaba |
1.1 |
} |
1469 |
|
|
} |
1470 |
|
|
if (ref $pre) { |
1471 |
|
|
# warn unmatched start-tag |
1472 |
|
|
} |
1473 |
|
|
} elsif ($line =~ /^\s/) { |
1474 |
|
|
$current->append_text ("\x0A"); |
1475 |
|
|
my $pre = $current->append_new_node (type => '#element', |
1476 |
|
|
namespace_uri => $NS_XHTML1, |
1477 |
|
|
local_name => 'pre'); |
1478 |
|
|
$pre->set_attribute (space => 'preserve', namespace_uri => NS_xml_URI); |
1479 |
wakaba |
1.4 |
__FUNCPACK__->inline_text_to_xml (\$line => $pre, %opt); |
1480 |
wakaba |
1.1 |
while ($$source =~ /\G([^\x0A]*)\x0A/gc) { |
1481 |
|
|
my $line = $1; |
1482 |
|
|
if (length $line == 0) { |
1483 |
|
|
pos ($$source) -= 1; |
1484 |
|
|
last; |
1485 |
wakaba |
1.4 |
} elsif ($opt{return_by_INS} and $line =~ /^\]INS\]\s*$/) { |
1486 |
|
|
return; |
1487 |
|
|
} elsif ($opt{return_by_DEL} and $line =~ /^\]DEL\]\s*$/) { |
1488 |
|
|
return; |
1489 |
wakaba |
1.1 |
} else { |
1490 |
|
|
$pre->append_text ("\x0A"); |
1491 |
wakaba |
1.4 |
__FUNCPACK__->inline_text_to_xml (\$line => $pre, %opt); |
1492 |
wakaba |
1.1 |
} |
1493 |
|
|
} |
1494 |
|
|
} elsif ($line =~ /^,/) { |
1495 |
|
|
$current->append_text ("\x0A"); |
1496 |
|
|
my $tbody = $current->append_new_node (type => '#element', |
1497 |
|
|
namespace_uri => $NS_XHTML2, |
1498 |
|
|
local_name => 'table') |
1499 |
|
|
->append_new_node (type => '#element', |
1500 |
|
|
namespace_uri => $NS_XHTML2, |
1501 |
|
|
local_name => 'tbody'); |
1502 |
wakaba |
1.4 |
__FUNCPACK__->tablerow_text_to_xml (\$line => $tbody, %opt); |
1503 |
wakaba |
1.1 |
while ($$source =~ /\G(,[^\x0A]*)\x0A/gc) { |
1504 |
wakaba |
1.4 |
__FUNCPACK__->tablerow_text_to_xml (\"$1" => $tbody, %opt); |
1505 |
wakaba |
1.1 |
} |
1506 |
|
|
} else { |
1507 |
|
|
my $current_type = $current->local_name; |
1508 |
|
|
if ($current_type eq 'section' |
1509 |
|
|
or $current_type eq 'body' |
1510 |
|
|
or $current_type eq 'bodytext' |
1511 |
wakaba |
1.4 |
or $current_type eq 'insert' |
1512 |
|
|
or $current_type eq 'delete') { |
1513 |
wakaba |
1.1 |
$current->append_text ("\x0A"); |
1514 |
|
|
if ($line =~ s/^__&&([^&]+)&&__//) { |
1515 |
|
|
$current->append_new_node (type => '#element', |
1516 |
|
|
namespace_uri => $NS_SW09, |
1517 |
|
|
local_name => 'replace') |
1518 |
|
|
->set_attribute (by => $1); |
1519 |
|
|
} elsif ($line =~ s/^\[\[$Reg_Form_Content_M\]\]//o) { |
1520 |
|
|
for ($current->append_new_node (type => '#element', |
1521 |
|
|
namespace_uri => $NS_SW09, |
1522 |
|
|
local_name => 'form')) { |
1523 |
|
|
$_->set_attribute (id => $1) if $1; |
1524 |
|
|
my ($i, $t, $o) = ($2, $3 || '', $4 || ''); |
1525 |
wakaba |
1.4 |
s/\\(.)/$1/g for ($i, $t, $o); |
1526 |
wakaba |
1.1 |
$_->set_attribute (input => $i); |
1527 |
|
|
$_->set_attribute (template => $t); |
1528 |
|
|
$_->set_attribute (option => $o); |
1529 |
|
|
} |
1530 |
|
|
} elsif ($line =~ s/^\[\[$Reg_Embed_Content_M\]\]//o) { |
1531 |
|
|
for ($current->append_new_node (type => '#element', |
1532 |
|
|
namespace_uri => $NS_SW09, |
1533 |
|
|
local_name => 'form')) { |
1534 |
|
|
$_->set_attribute (ref => $1); |
1535 |
|
|
$_->set_attribute (id => $2) if $2; |
1536 |
|
|
$_->set_attribute (parameter => $3) if defined $3; |
1537 |
|
|
} |
1538 |
|
|
} |
1539 |
wakaba |
1.4 |
if (length $line) { |
1540 |
|
|
$current = $current->append_new_node |
1541 |
|
|
(type => '#element', |
1542 |
|
|
namespace_uri => $NS_XHTML2, |
1543 |
|
|
local_name => 'p'); |
1544 |
|
|
__FUNCPACK__->inline_text_to_xml (\$line => $current, %opt); |
1545 |
|
|
} |
1546 |
wakaba |
1.1 |
} else { |
1547 |
wakaba |
1.4 |
$current->append_text ("\x0A"); # replacement of prev.line's \n |
1548 |
|
|
__FUNCPACK__->inline_text_to_xml (\$line => $current, %opt); |
1549 |
wakaba |
1.1 |
} |
1550 |
|
|
} |
1551 |
|
|
} |
1552 |
|
|
|
1553 |
|
|
if ($opt{return_by_INS} or $opt{return_by_DEL}) { |
1554 |
|
|
# warn |
1555 |
|
|
} |
1556 |
|
|
|
1557 |
|
|
Function: |
1558 |
|
|
@Name: tablerow_text_to_xml |
1559 |
|
|
@Description: |
1560 |
|
|
@@@: |
1561 |
|
|
SuikaWiki/0.9 text format to XML representation - table row |
1562 |
|
|
@@lang:en |
1563 |
|
|
@Main: |
1564 |
|
|
my (undef, $source => $current, %opt) = @_; |
1565 |
|
|
$current->append_text ("\x0A"); |
1566 |
|
|
$current = $current->append_new_node (type => '#element', |
1567 |
|
|
namespace_uri => $NS_XHTML2, |
1568 |
|
|
local_name => 'tr'); |
1569 |
|
|
my $prev_cell; |
1570 |
|
|
while ($$source =~ /\G,\s*/gc) { |
1571 |
wakaba |
1.4 |
$$source =~ /\G([^,"][^,]*|"(?>[^"\\]*)(?>(?>[^"\\]+|\\.)*)"\s*)/gc; |
1572 |
wakaba |
1.1 |
my $cell = $1; |
1573 |
|
|
if ($cell =~ s/^"//) { |
1574 |
|
|
$cell =~ s/"\s*$//g; |
1575 |
|
|
$cell =~ s/\\(.)/$1/g; |
1576 |
|
|
} else { |
1577 |
|
|
$cell =~ s/\s+$//g; |
1578 |
|
|
if ($cell eq '==') { |
1579 |
|
|
if (ref $prev_cell) { |
1580 |
|
|
$prev_cell->set_attribute (colspan => |
1581 |
|
|
$prev_cell->get_attribute_value ('colspan', default => 1) |
1582 |
|
|
+ 1); |
1583 |
|
|
next; |
1584 |
|
|
} else { |
1585 |
|
|
# TODO: warn |
1586 |
|
|
} |
1587 |
|
|
} |
1588 |
|
|
} |
1589 |
|
|
$prev_cell = $current->append_new_node |
1590 |
|
|
(type => '#element', |
1591 |
|
|
namespace_uri => $NS_XHTML2, |
1592 |
|
|
local_name => 'td'); |
1593 |
wakaba |
1.4 |
__FUNCPACK__->inline_text_to_xml (\$cell => $prev_cell, %opt); |
1594 |
wakaba |
1.1 |
} |
1595 |
|
|
# TODO: warn |
1596 |
|
|
|
1597 |
|
|
Function: |
1598 |
|
|
@Name: inline_text_to_xml |
1599 |
|
|
@Description: |
1600 |
|
|
@@@: |
1601 |
|
|
SuikaWiki/0.9 text format to XML representation - inline level elements |
1602 |
|
|
@@lang:en |
1603 |
|
|
@Main: |
1604 |
|
|
my $ElementDef = { |
1605 |
wakaba |
1.5 |
ABBR => {ln => 'abbr', ns_uri => $NS_XHTML2}, |
1606 |
wakaba |
1.1 |
CODE => {ln => 'code', ns_uri => $NS_XHTML2}, |
1607 |
|
|
DEL => {ln => 'del', ns_uri => $NS_XHTML1}, |
1608 |
|
|
DFN => {ln => 'dfn', ns_uri => $NS_XHTML2}, |
1609 |
|
|
INS => {ln => 'ins', ns_uri => $NS_XHTML1}, |
1610 |
|
|
KBD => {ln => 'kbd', ns_uri => $NS_XHTML2}, |
1611 |
|
|
Q => {ln => 'q', ns_uri => $NS_XHTML1}, |
1612 |
|
|
RUBY => {ln => 'ruby', ns_uri => $NS_XHTML2}, |
1613 |
|
|
RUBYB => {ln => 'rubyb', ns_uri => $NS_SW09}, |
1614 |
|
|
SAMP => {ln => 'samp', ns_uri => $NS_XHTML2}, |
1615 |
|
|
SUB => {ln => 'sub', ns_uri => $NS_XHTML2}, |
1616 |
|
|
SUP => {ln => 'sup', ns_uri => $NS_XHTML2}, |
1617 |
|
|
VAR => {ln => 'var', ns_uri => $NS_XHTML2}, |
1618 |
|
|
WEAK => {ln => 'weak', ns_uri => $NS_SW09}, |
1619 |
|
|
anchor => {ln => 'anchor', ns_uri => $NS_SW09, has_fragment_no => 1}, |
1620 |
|
|
del => {has_cite => 1}, |
1621 |
|
|
ins => {has_cite => 1}, |
1622 |
|
|
q => {has_cite => 1}, |
1623 |
|
|
rb => {ln => 'rb', ns_uri => $NS_XHTML2, is_nested => 1}, |
1624 |
|
|
rt => {ln => 'rt', ns_uri => $NS_XHTML2, is_nested => 1}, |
1625 |
|
|
}; |
1626 |
|
|
|
1627 |
|
|
my (undef, $source => $current, %opt) = @_; |
1628 |
|
|
if ($$source =~ /\G\[([0-9]+)\]/gc) { |
1629 |
|
|
for ($current->append_new_node (type => '#element', |
1630 |
|
|
namespace_uri => $NS_SW09, |
1631 |
|
|
local_name => 'anchor-end')) { |
1632 |
wakaba |
1.4 |
$_->set_attribute (anchor => 0+$1, |
1633 |
|
|
namespace_uri => $NS_SW09); |
1634 |
wakaba |
1.1 |
$_->append_text ('['.$1.']'); |
1635 |
|
|
} |
1636 |
|
|
} |
1637 |
|
|
my $depth = 0; |
1638 |
|
|
while (pos $$source < length $$source) { |
1639 |
|
|
if ($$source =~ /\G\[\[(?=\#)/gc) { |
1640 |
|
|
my $form = $current->append_new_node (type => '#element', |
1641 |
|
|
namespace_uri => $NS_SW09, |
1642 |
|
|
local_name => 'form'); |
1643 |
|
|
if ($$source =~ /\G$Reg_Form_Content_M\]\]/ogc) { |
1644 |
|
|
$form->set_attribute (id => $1) if $1; |
1645 |
wakaba |
1.4 |
my ($i, $t, $o) = ($2, $3, $4); |
1646 |
|
|
s/\\(.)/$1/g for ($i, $t, $o); |
1647 |
|
|
$form->set_attribute (input => $i); |
1648 |
|
|
$form->set_attribute (template => $t); |
1649 |
|
|
$form->set_attribute (option => $o); |
1650 |
wakaba |
1.1 |
} elsif ($$source =~ /\G$Reg_Embed_Content_M\]\]/ogc) { |
1651 |
|
|
$form->set_attribute (ref => $1); |
1652 |
|
|
$form->set_attribute (id => $2) if $2; |
1653 |
|
|
$form->set_attribute (parameter => $3) if defined $3; |
1654 |
|
|
} else { |
1655 |
|
|
## TODO: error |
1656 |
wakaba |
1.4 |
SuikaWiki::Plugin->module_package('Error')->report_error_simple ($opt{opt}->{o}->{wiki}, InvalidForm => substr ($$source, pos ($$source))); |
1657 |
wakaba |
1.1 |
} |
1658 |
|
|
} elsif ($$source =~ /\G\[(?>([A-Z]+)(?>\(([^)]*)\))?)?\[/gc) { |
1659 |
|
|
my $type = $1 || 'anchor'; |
1660 |
|
|
my $param = $2; |
1661 |
|
|
my $def = $ElementDef->{ $type }; |
1662 |
|
|
unless ($def) { |
1663 |
|
|
## TODO: error |
1664 |
wakaba |
1.4 |
$def = $ElementDef->{CODE}; |
1665 |
wakaba |
1.1 |
} |
1666 |
|
|
$current = $current->append_new_node (type => '#element', |
1667 |
|
|
namespace_uri => $def->{ns_uri}, |
1668 |
|
|
local_name => $def->{ln}); |
1669 |
|
|
$current->set_attribute (class => $param) if $param; |
1670 |
|
|
if ($type eq 'RUBY' or $type eq 'RUBYB' |
1671 |
|
|
or $type eq 'ABBR') { |
1672 |
|
|
$current = $current->append_new_node |
1673 |
|
|
(type => '#element', |
1674 |
|
|
namespace_uri => $ElementDef->{rb}->{ns_uri}, |
1675 |
|
|
local_name => $ElementDef->{rb}->{ln}); |
1676 |
|
|
} |
1677 |
|
|
$depth++; |
1678 |
|
|
} elsif ($$source =~ /\G\](?> <([0-9A-Za-z_+.%-]+):($Reg_URI_Opaque)> |
1679 |
|
|
\ | >>([0-9]+) )? |
1680 |
|
|
\ \]/gcox) { |
1681 |
|
|
my ($scheme, $opaque, $anchor) = ($1, $2, $3); |
1682 |
|
|
unless ($depth) { |
1683 |
|
|
$current->append_text (substr ($$source, $-[0], $+[0]-$-[0])); |
1684 |
|
|
next; |
1685 |
|
|
} |
1686 |
|
|
my $def = $ElementDef->{$current->local_name} || {}; |
1687 |
|
|
if (defined $anchor) { |
1688 |
wakaba |
1.4 |
$current->set_attribute (anchor => $anchor + 0, |
1689 |
|
|
namespace_uri => $NS_SW09); |
1690 |
|
|
} elsif (defined $scheme) { |
1691 |
|
|
if ($scheme =~ /[A-Z]/) { |
1692 |
|
|
$current->set_attribute (resScheme => $scheme, |
1693 |
|
|
namespace_uri => $NS_SW09); |
1694 |
|
|
$current->set_attribute (resParameter => $opaque, |
1695 |
|
|
namespace_uri => $NS_SW09); |
1696 |
wakaba |
1.1 |
} else { |
1697 |
wakaba |
1.4 |
$current->set_attribute (resScheme => 'URI', |
1698 |
wakaba |
1.1 |
namespace_uri => $NS_SW09); |
1699 |
wakaba |
1.4 |
$current->set_attribute (resParameter => "$scheme:$opaque", |
1700 |
wakaba |
1.1 |
namespace_uri => $NS_SW09); |
1701 |
|
|
} |
1702 |
|
|
} |
1703 |
|
|
$current = $current->parent_node; |
1704 |
|
|
$current = $current->parent_node if $def->{is_nested}; |
1705 |
|
|
$depth--; |
1706 |
wakaba |
1.4 |
} elsif ($$source =~ /\G\]\s*\[/gc) { |
1707 |
wakaba |
1.1 |
if ($current->local_name eq 'rb' or $current->local_name eq 'rt') { |
1708 |
|
|
$current = $current->parent_node |
1709 |
|
|
->append_new_node |
1710 |
|
|
(type => '#element', |
1711 |
|
|
namespace_uri => $ElementDef->{rt}->{ns_uri}, |
1712 |
|
|
local_name => $ElementDef->{rt}->{ln}); |
1713 |
|
|
} else { |
1714 |
wakaba |
1.4 |
$current->append_text (substr ($$source, $-[0], $+[0]-$-[0])); |
1715 |
wakaba |
1.1 |
} |
1716 |
|
|
} elsif ($$source =~ /\G'''?/gc) { |
1717 |
|
|
my $type = $+[0] - $-[0] == 3 ? 'strong' : 'em'; |
1718 |
|
|
if ($current->local_name eq $type) { |
1719 |
|
|
$current = $current->parent_node; |
1720 |
|
|
} else { |
1721 |
|
|
$current = $current->append_new_node |
1722 |
|
|
(type => '#element', |
1723 |
|
|
namespace_uri => $NS_XHTML2, |
1724 |
|
|
local_name => $type); |
1725 |
|
|
} |
1726 |
|
|
} elsif ($$source =~ /\G<([0-9A-Za-z_+.%-]+):($Reg_URI_Opaque)>/gc) { |
1727 |
|
|
my ($scheme, $data) = ($1, $2); |
1728 |
|
|
my $link = $current->append_new_node |
1729 |
|
|
(type => '#element', |
1730 |
|
|
namespace_uri => $NS_SW09, |
1731 |
wakaba |
1.2 |
local_name => 'anchor-external'); |
1732 |
wakaba |
1.1 |
if (substr ($scheme, 0, 1) =~ /[A-Z]/) { |
1733 |
wakaba |
1.4 |
$link->set_attribute (resScheme => $scheme, |
1734 |
|
|
namespace_uri => $NS_SW09); |
1735 |
|
|
$link->set_attribute (resParameter => $data, |
1736 |
|
|
namespace_uri => $NS_SW09); |
1737 |
wakaba |
1.1 |
} else { # URI Reference |
1738 |
wakaba |
1.4 |
$link->set_attribute (resScheme => 'URI', |
1739 |
|
|
namespace_uri => $NS_SW09); |
1740 |
|
|
$link->set_attribute (resParameter => $scheme.':'.$data, |
1741 |
|
|
namespace_uri => $NS_SW09); |
1742 |
wakaba |
1.1 |
} |
1743 |
wakaba |
1.3 |
$link->append_text ($scheme.':'.$data); |
1744 |
wakaba |
1.1 |
} elsif ($$source =~ /\G__&&/gc) { |
1745 |
|
|
if ($$source =~ /\G([^&]+)&&__/gc) { |
1746 |
|
|
$current->append_new_node |
1747 |
|
|
(type => '#element', |
1748 |
|
|
namespace_uri => $NS_SW09, |
1749 |
wakaba |
1.2 |
local_name => 'replace') |
1750 |
wakaba |
1.1 |
->set_attribute (by => $1); |
1751 |
|
|
} else { |
1752 |
wakaba |
1.2 |
$current->append_text ('__&&'); |
1753 |
wakaba |
1.1 |
} |
1754 |
|
|
} elsif ($$source =~ /\G((?> |
1755 |
wakaba |
1.4 |
[^'\[\]<>_]+ |
1756 |
wakaba |
1.1 |
| ' (?!') |
1757 |
wakaba |
1.4 |
| \[ (?!\[|[A-Z]+(?>\([^()\\]* |
1758 |
|
|
(?>[^()\\]+|\\.)*\))?\[) |
1759 |
wakaba |
1.1 |
| \] (?! \] |
1760 |
|
|
| >>[0-9]+\] |
1761 |
|
|
| <[0-9A-Za-z_+.%-]+:$Reg_URI_Opaque>\] |
1762 |
|
|
| \s*\[ ) |
1763 |
|
|
| < (?![0-9A-Za-z_+.%-]+:$Reg_URI_Opaque>) |
1764 |
|
|
| > (?!>[0-9]) |
1765 |
|
|
| _ (?!_&&) |
1766 |
|
|
)+)/oxgc) { |
1767 |
|
|
$current->append_text ($1); |
1768 |
|
|
} elsif ($$source =~ /\G>>([0-9]+)/gc) { |
1769 |
|
|
for ($current->append_new_node (type => '#element', |
1770 |
|
|
namespace_uri => $NS_SW09, |
1771 |
wakaba |
1.2 |
local_name => 'anchor-internal')) { |
1772 |
wakaba |
1.4 |
$_->set_attribute (anchor => 0+$1, |
1773 |
|
|
namespace_uri => $NS_SW09); |
1774 |
wakaba |
1.1 |
$_->append_text ('>>'.$1); |
1775 |
|
|
} |
1776 |
|
|
} else { |
1777 |
wakaba |
1.4 |
CORE::die "Implementation buggy: ", substr ($$source, pos $$source); |
1778 |
wakaba |
1.1 |
} |
1779 |
|
|
} |
1780 |
|
|
|
1781 |
wakaba |
1.2 |
FormattingRule: |
1782 |
wakaba |
1.3 |
@Category[list]: |
1783 |
|
|
page-link |
1784 |
|
|
link-to-resource |
1785 |
wakaba |
1.2 |
@Name: sw09--link-anchor-content |
1786 |
|
|
@Description: |
1787 |
|
|
@@@: |
1788 |
|
|
Output content of the anchor element |
1789 |
|
|
@@lang:en |
1790 |
|
|
@Formatting: |
1791 |
|
|
if ($o->{var}->{sw09__anchor_content}) { |
1792 |
|
|
$o->{var}->{sw09__anchor_content}->($p->{-parent}); |
1793 |
|
|
} else { |
1794 |
wakaba |
1.4 |
SuikaWiki::Plugin->module_package ('WikiResource') |
1795 |
|
|
->append_tree |
1796 |
|
|
(name => 'Link:SuikaWiki/0.9:link-anchor-content:InvalidContext', |
1797 |
|
|
param => $o, |
1798 |
|
|
-parent => $p->{-parent}, |
1799 |
|
|
wiki => $o->{wiki}); |
1800 |
wakaba |
1.2 |
} |
1801 |
|
|
|
1802 |
|
|
Resource: |
1803 |
|
|
@Link:SuikaWiki/0.9:link-anchor-content:InvalidContext: |
1804 |
wakaba |
1.4 |
@@@: %percent;sw09--link-anchor-content; cannot be used in this context. |
1805 |
wakaba |
1.2 |
@@lang:en |
1806 |
wakaba |
1.3 |
@Link:SuikaWiki/0.9:toResource:SourceLabel: |
1807 |
|
|
@@@: |
1808 |
|
|
%select_link_resource_scheme ( |
1809 |
|
|
URI => {<%link-to-it( |
1810 |
|
|
label=>{%link-resource-parameters;}p, |
1811 |
|
|
);>}, |
1812 |
|
|
MAIL => {<%link-to-it( |
1813 |
|
|
label => {%link-resource-parameters;}p, |
1814 |
|
|
description |
1815 |
|
|
=> {%res (name=>{Link:MailAddress=});<%link-resource-parameters;>}p, |
1816 |
|
|
);>}, |
1817 |
|
|
otherwise => {<%link-to-it( |
1818 |
|
|
label => {%sw09--link-anchor-content;}p, |
1819 |
|
|
description => {%res (name=>{Link:URIReference=});<%uri-reference;>}p, |
1820 |
|
|
);>}, |
1821 |
|
|
); |
1822 |
|
|
@@lang:en |
1823 |
wakaba |
1.2 |
@Link:SuikaWiki/0.9:toWikiPage:SourceLabel: |
1824 |
|
|
@@@: |
1825 |
|
|
%link-to-it( |
1826 |
|
|
label=>{%sw09--link-anchor-content;%if-linked-wikipage-exist( |
1827 |
|
|
true=>{%if-link-has-dest-anchor-no(true=>{>>%link-dest-anchor-no;});}, |
1828 |
|
|
false=>{%res(name=>{Link:toWikiPage:NotExist:Mark});} |
1829 |
|
|
);}p, |
1830 |
|
|
description=>{%page-name(absolute);; %if-linked-wikipage-exist( |
1831 |
|
|
true=>{%page-headline;}, |
1832 |
|
|
false=>{(%res(name=>{Link:toWikiPage:NotExist:Description});)}, |
1833 |
|
|
);}p, |
1834 |
|
|
class=>{%if-linked-wikipage-exist(false=>{not-exist});}p, |
1835 |
|
|
); |
1836 |
wakaba |
1.5 |
@SuikaWiki/0.9:form:comment:input: |
1837 |
|
|
%line (content => {%textarea (id=>msg,size=>20,lines=>3);}p); |
1838 |
|
|
%line (content => { |
1839 |
|
|
(%text (description => {%res (name => {Form:Description:HumanName});}p, |
1840 |
|
|
id => name, size => 6); |
1841 |
|
|
[%text (description => |
1842 |
|
|
{%res (name => {Form:Description:MailAddress});}p, |
1843 |
|
|
id => mail, size => 5);] |
1844 |
|
|
%check (default, id => record-date, |
1845 |
|
|
label => {%res (name => {Form:Label:LogDate});}p, |
1846 |
|
|
description => {%res (name => {Form:Description:LogDate});}p);) |
1847 |
|
|
%submit (label => {%res (name => {Form:Label:Add});}p, |
1848 |
|
|
description => {%res (name => {Form:Description:Add});}p); |
1849 |
|
|
%we--update-lastmodified-datetime; |
1850 |
|
|
}p); |
1851 |
|
|
@SuikaWiki/0.9:form:comment:template: |
1852 |
|
|
%n |
1853 |
|
|
;[%index;]%n |
1854 |
|
|
;%text(source=>msg);%n;(%name;%text(source=>mail,prefix=>" [",suffix=>"]");%iif(source=>record-date,true=>" [WEAK[%date;]]");)%n; |
1855 |
|
|
@SuikaWiki/0.9:form:comment:option: |
1856 |
|
|
%require (msg); |
1857 |
|
|
@SuikaWiki/0.9:form:footannotate:input: |
1858 |
|
|
%line (content => {%textarea (id=>msg,size=>20,lines=>3);}p); |
1859 |
|
|
%line (content => { |
1860 |
|
|
(%text (description => {%res (name => {Form:Description:HumanName});}p, |
1861 |
|
|
id => name, size => 6); |
1862 |
|
|
[%text (description => |
1863 |
|
|
{%res (name => {Form:Description:MailAddress});}p, |
1864 |
|
|
id => mail, size => 5);] |
1865 |
|
|
%check (default, id => record-date, |
1866 |
|
|
label => {%res (name => {Form:Label:LogDate});}p, |
1867 |
|
|
description => {%res (name => {Form:Description:LogDate});}p);) |
1868 |
|
|
%submit (label => {%res (name => {Form:Label:Add});}p, |
1869 |
|
|
description => {%res (name => {Form:Description:Add});}p); |
1870 |
|
|
%we--update-lastmodified-datetime; |
1871 |
|
|
}p); |
1872 |
|
|
@SuikaWiki/0.9:form:footannotate:template: |
1873 |
|
|
%n |
1874 |
|
|
;[%index;]%n |
1875 |
|
|
;%text(source=>msg);%n |
1876 |
|
|
;(%name;%text(source=>mail,prefix=>" [",suffix=>"]");%iif(source=>record-date,true=>" [WEAK[%date;]]");)%n; |
1877 |
|
|
@SuikaWiki/0.9:form:footannotate:option: |
1878 |
|
|
%require (msg); |
1879 |
wakaba |
1.3 |
|
1880 |
wakaba |
1.4 |
Error: |
1881 |
|
|
@Name: text_parse |
1882 |
|
|
@Definition: |
1883 |
|
|
@@INLINE_NO_CLOSE_TAG: |
1884 |
|
|
@@@description: |
1885 |
|
|
Close tag of element "%t (name => element_type);" not found. |
1886 |
|
|
@@@level: non-fatal |
1887 |
|
|
@@BLOCK_NO_CLOSE_TAG: |
1888 |
|
|
@@@description: |
1889 |
|
|
Close tag of element "%t (name => element_type);" not found. |
1890 |
|
|
@@@level: non-fatal |
1891 |
|
|
@@INVALID_FORM: |
1892 |
|
|
@@@description: |
1893 |
|
|
Invalid syntax of WikiForm |
1894 |
|
|
@@@level: non-fatal |
1895 |
|
|
|
1896 |
|
|
Error: |
1897 |
|
|
@Name: xml_to_text |
1898 |
|
|
@IsA[list]: |
1899 |
|
|
::SuikaWiki::Format:: |
1900 |
|
|
@Definition: |
1901 |
|
|
@@ |