1 |
Module: |
2 |
@QName: Markup|H2H |
3 |
@enFN: |
4 |
H2H/0.9 and H2H/1.0 Document Markup Language DOM |
5 |
@enDesc: |
6 |
{TODO:: |
7 |
|
8 |
} |
9 |
|
10 |
@Namespace: |
11 |
http://suika.fam.cx/~wakaba/archive/2005/manakai/Markup/H2H/ |
12 |
|
13 |
@DISCore:author: DISCore|Wakaba |
14 |
@License: license|Perl+MPL |
15 |
@Date: |
16 |
$Date: 2006/05/06 11:44:26 $ |
17 |
|
18 |
@Require: |
19 |
@@Module: |
20 |
@@@QName: Markup|common |
21 |
@@Module: |
22 |
@@@QName: MDOM|TreeCore |
23 |
@@@WithFor: ManakaiDOM|ManakaiDOMLatest |
24 |
@@Module: |
25 |
@@@WithFor: ManakaiDOM|ManakaiDOM |
26 |
@@Module: |
27 |
@@@WithFor: ManakaiDOM|ManakaiDOMLatest |
28 |
@@Module: |
29 |
@@@QName: Markup|Atom |
30 |
@@@WithFor: ManakaiDOM|ManakaiDOMLatest |
31 |
@DefaultFor: ManakaiDOM|ManakaiDOMLatest |
32 |
|
33 |
Namespace: |
34 |
@aa: |
35 |
http://pc5.2ch.net/test/read.cgi/hp/1096723178/aavocab# |
36 |
@c: |
37 |
http://suika.fam.cx/~wakaba/archive/2004/8/18/dom-core# |
38 |
@cfg: |
39 |
http://suika.fam.cx/www/2006/dom-config/ |
40 |
@dis: |
41 |
http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis-- |
42 |
@doc: |
43 |
http://suika.fam.cx/~wakaba/archive/2005/7/tutorial# |
44 |
@d: |
45 |
http://suika.fam.cx/~wakaba/archive/2004/dom/xdt# |
46 |
@DOMMain: |
47 |
http://suika.fam.cx/~wakaba/archive/2004/dom/main# |
48 |
@dx: |
49 |
http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/Error/DOMException# |
50 |
@ecore: |
51 |
http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/Error/Core/ |
52 |
@f: |
53 |
http://suika.fam.cx/~wakaba/archive/2004/dom/feature# |
54 |
@fe: |
55 |
http://suika.fam.cx/www/2006/feature/ |
56 |
@gls: |
57 |
http://suika.fam.cx/~wakaba/archive/2004/dom/gls# |
58 |
@h2h: |
59 |
http://suika.fam.cx/~wakaba/archive/2005/manakai/Markup/H2H/ |
60 |
@html: |
61 |
http://www.w3.org/1999/xhtml |
62 |
@idl: |
63 |
http://suika.fam.cx/~wakaba/archive/2004/dis/IDL# |
64 |
@kwd: |
65 |
http://suika.fam.cx/~wakaba/archive/2005/rfc2119/ |
66 |
@lang: |
67 |
http://suika.fam.cx/~wakaba/archive/2004/8/18/lang# |
68 |
@license: |
69 |
http://suika.fam.cx/~wakaba/archive/2004/8/18/license# |
70 |
@ManakaiDOM: |
71 |
http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom# |
72 |
@Markup: |
73 |
http://suika.fam.cx/~wakaba/archive/2005/manakai/Markup# |
74 |
@mat: |
75 |
http://suika.fam.cx/~wakaba/archive/2005/manakai/Markup/Atom/ |
76 |
@MDOM: |
77 |
http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#ManakaiDOM. |
78 |
@MDOMX: |
79 |
http://suika.fam.cx/~wakaba/archive/2004/8/4/manakai-dom-exception# |
80 |
@dlp: |
81 |
http://suika.fam.cx/~wakaba/archive/2004/dis/Perl# |
82 |
@html3: |
83 |
urn:x-suika-fam-cx:markup:ietf:html:3:draft:00: |
84 |
@html5: |
85 |
http://www.w3.org/1999/xhtml |
86 |
@rel: |
87 |
http://www.iana.org/assignments/relation/ |
88 |
@s: |
89 |
http://suika.fam.cx/~wakaba/archive/2004/dis/Markup# |
90 |
@sw09: |
91 |
urn:x-suika-fam-cx:markup:suikawiki:0:9: |
92 |
@sw010: |
93 |
urn:x-suika-fam-cx:markup:suikawiki:0:10: |
94 |
@tc: |
95 |
http://suika.fam.cx/~wakaba/archive/2005/manakai/DOM/TreeCore/ |
96 |
@td: |
97 |
http://suika.fam.cx/~wakaba/archive/2005/manakai/DOM/Document/ |
98 |
@te: |
99 |
http://suika.fam.cx/~wakaba/archive/2005/manakai/DOM/Element/ |
100 |
@test: |
101 |
http://suika.fam.cx/~wakaba/archive/2004/dis/Test# |
102 |
@tx: |
103 |
http://suika.fam.cx/~wakaba/archive/2005/manakai/DOM/XML/ |
104 |
@urigen: |
105 |
http://suika.fam.cx/~wakaba/archive/2005/manakai/URI/Generic/ |
106 |
@xhtml2: |
107 |
http://www.w3.org/2002/06/xhtml2/ |
108 |
@xml: |
109 |
http://www.w3.org/XML/1998/namespace |
110 |
@xmlns: |
111 |
http://www.w3.org/2000/xmlns/ |
112 |
|
113 |
ElementTypeBinding: |
114 |
@Name: CODE |
115 |
@ElementType: |
116 |
dis:ResourceDef |
117 |
@ShadowContent: |
118 |
@@DISCore:resourceType: dlp|BlockCode |
119 |
@@ForCheck: ManakaiDOM|ForClass |
120 |
|
121 |
ElementTypeBinding: |
122 |
@Name: Method |
123 |
@ElementType: |
124 |
dis:ResourceDef |
125 |
@ShadowContent: |
126 |
@@DISCore:resourceType: DISLang|Method |
127 |
@@ForCheck: !=ManakaiDOM|ManakaiDOM |
128 |
|
129 |
ElementTypeBinding: |
130 |
@Name: Param |
131 |
@ElementType: |
132 |
dis:ResourceDef |
133 |
@ShadowContent: |
134 |
@@DISCore:resourceType: DISLang|MethodParameter |
135 |
|
136 |
ElementTypeBinding: |
137 |
@Name: Return |
138 |
@ElementType: |
139 |
dis:ResourceDef |
140 |
@ShadowContent: |
141 |
@@DISCore:resourceType: DISLang|MethodReturn |
142 |
|
143 |
ElementTypeBinding: |
144 |
@Name: Attr |
145 |
@ElementType: |
146 |
dis:ResourceDef |
147 |
@ShadowContent: |
148 |
@@DISCore:resourceType: DISLang|Attribute |
149 |
@@ForCheck: !=ManakaiDOM|ManakaiDOM |
150 |
|
151 |
ElementTypeBinding: |
152 |
@Name: Get |
153 |
@ElementType: |
154 |
dis:ResourceDef |
155 |
@ShadowContent: |
156 |
@@DISCore:resourceType: DISLang|AttributeGet |
157 |
|
158 |
ElementTypeBinding: |
159 |
@Name: Set |
160 |
@ElementType: |
161 |
dis:ResourceDef |
162 |
@ShadowContent: |
163 |
@@DISCore:resourceType: DISLang|AttributeSet |
164 |
|
165 |
ElementTypeBinding: |
166 |
@Name: nullCase |
167 |
@ElementType: |
168 |
dis:ResourceDef |
169 |
@ShadowContent: |
170 |
@@DISCore:resourceType: ManakaiDOM|InCase |
171 |
@@Value: |
172 |
@@@is-null:1 |
173 |
|
174 |
ElementTypeBinding: |
175 |
@Name: PerlDef |
176 |
@ElementType: |
177 |
dis:Def |
178 |
@ShadowContent: |
179 |
@@ContentType: lang|Perl |
180 |
@@ForCheck: ManakaiDOM|ForClass |
181 |
|
182 |
ElementTypeBinding: |
183 |
@Name: PerlCDef |
184 |
@ElementType: |
185 |
dis:Def |
186 |
@ShadowContent: |
187 |
@@ContentType: lang|Perl |
188 |
|
189 |
ElementTypeBinding: |
190 |
@Name: enImplNote |
191 |
@ElementType: |
192 |
dis:ImplNote |
193 |
@ShadowContent: |
194 |
@@lang:en |
195 |
|
196 |
ElementTypeBinding: |
197 |
@Name: enFN |
198 |
@ElementType: |
199 |
dis:FullName |
200 |
@ShadowContent: |
201 |
@@lang:en |
202 |
|
203 |
ElementTypeBinding: |
204 |
@Name: PTests |
205 |
@ElementType: |
206 |
dis:ResourceDef |
207 |
@ShadowContent: |
208 |
@@ForCheck: ManakaiDOM|ForClass |
209 |
@@DISCore:resourceType: test|ParserTestSet |
210 |
|
211 |
ElementTypeBinding: |
212 |
@Name: PTest |
213 |
@ElementType: |
214 |
dis:ResourceDef |
215 |
@ShadowContent: |
216 |
@@ForCheck: ManakaiDOM|ForClass |
217 |
@@DISCore:resourceType: test|ParserTest |
218 |
|
219 |
ElementTypeBinding: |
220 |
@Name: DEnt |
221 |
@ElementType: |
222 |
dis:ResourceDef |
223 |
@ShadowContent: |
224 |
@@DISCore:resourceType: test|RootEntity |
225 |
|
226 |
ElementTypeBinding: |
227 |
@Name: IFClsETDef |
228 |
@ElementType: |
229 |
dis:ResourceDef |
230 |
@ShadowContent: |
231 |
@@DISCore:resourceType: |
232 |
@@@@: dis|MultipleResource |
233 |
@@@ForCheck: !ManakaiDOM|ForIF !ManakaiDOM|ForClass !s|ForML |
234 |
@@resourceFor: ManakaiDOM|ForIF |
235 |
@@resourceFor: ManakaiDOM|ForClass |
236 |
@@resourceFor: s|ForML |
237 |
@@For: ManakaiDOM|ManakaiDOM |
238 |
|
239 |
@@DISCore:resourceType: |
240 |
@@@@: DISLang|Interface |
241 |
@@@ForCheck: ManakaiDOM|ForIF |
242 |
|
243 |
@@DISCore:resourceType: |
244 |
@@@@: DISLang|Class |
245 |
@@@ForCheck: ManakaiDOM|ForClass |
246 |
@@Implement: |
247 |
@@@@: ||ManakaiDOM|ManakaiDOM||ManakaiDOM|ForIF |
248 |
@@@ContentType: DISCore|TFPQNames |
249 |
@@@ForCheck: ManakaiDOM|ForClass ManakaiDOM|ManakaiDOM |
250 |
@@Implement: |
251 |
@@@@: ||ManakaiDOM|ManakaiDOMLatest||ManakaiDOM|ForIF |
252 |
@@@ContentType: DISCore|TFPQNames |
253 |
@@@ForCheck: ManakaiDOM|ForClass ManakaiDOM|ManakaiDOMLatest |
254 |
|
255 |
@@s:elementType: |
256 |
@@@@: ||+||s|ForML |
257 |
@@@ContentType: DISCore|TFPQNames |
258 |
@@@DISCore:stopISARecursive:1 |
259 |
|
260 |
@@DISCore:resourceType: |
261 |
@@@@: s|ElementType |
262 |
@@@ForCheck: s|ForML |
263 |
|
264 |
@@f:implements: AtomFeature10 |
265 |
|
266 |
ElementTypeBinding: |
267 |
@Name: IFClsDef |
268 |
@ElementType: |
269 |
dis:ResourceDef |
270 |
@ShadowContent: |
271 |
@@DISCore:resourceType: |
272 |
@@@@: dis|MultipleResource |
273 |
@@@ForCheck: !ManakaiDOM|ForIF !ManakaiDOM|ForClass !s|ForML |
274 |
@@resourceFor: ManakaiDOM|ForIF |
275 |
@@resourceFor: ManakaiDOM|ForClass |
276 |
@@For: ManakaiDOM|ManakaiDOM |
277 |
|
278 |
@@DISCore:resourceType: |
279 |
@@@@: DISLang|Interface |
280 |
@@@ForCheck: ManakaiDOM|ForIF |
281 |
|
282 |
@@DISCore:resourceType: |
283 |
@@@@: DISLang|Class |
284 |
@@@ForCheck: ManakaiDOM|ForClass |
285 |
@@Implement: |
286 |
@@@@: ||ManakaiDOM|ManakaiDOM||ManakaiDOM|ForIF |
287 |
@@@ContentType: DISCore|TFPQNames |
288 |
@@@ForCheck: ManakaiDOM|ForClass ManakaiDOM|ManakaiDOM |
289 |
@@Implement: |
290 |
@@@@: ||ManakaiDOM|ManakaiDOMLatest||ManakaiDOM|ForIF |
291 |
@@@ContentType: DISCore|TFPQNames |
292 |
@@@ForCheck: ManakaiDOM|ForClass ManakaiDOM|ManakaiDOMLatest |
293 |
|
294 |
@@f:implements: AtomFeature10 |
295 |
|
296 |
ElementTypeBinding: |
297 |
@Name: IFQName |
298 |
@ElementType: |
299 |
dis:QName |
300 |
@ShadowContent: |
301 |
@@ForCheck: ManakaiDOM|ForIF |
302 |
|
303 |
ElementTypeBinding: |
304 |
@Name: ClsQName |
305 |
@ElementType: |
306 |
dis:QName |
307 |
@ShadowContent: |
308 |
@@ForCheck: ManakaiDOM|ForClass |
309 |
|
310 |
ElementTypeBinding: |
311 |
@Name: ETRQName |
312 |
@ElementType: |
313 |
dis:QName |
314 |
@ShadowContent: |
315 |
@@ForCheck: s|ForML |
316 |
|
317 |
ElementTypeBinding: |
318 |
@Name: ETQName |
319 |
@ElementType: |
320 |
dis:AppName |
321 |
@ShadowContent: |
322 |
@@ForCheck: s|ForML |
323 |
@@ContentType: DISCore|QName |
324 |
|
325 |
ElementTypeBinding: |
326 |
@Name: IFISA |
327 |
@ElementType: |
328 |
dis:ISA |
329 |
@ShadowContent: |
330 |
@@ForCheck: ManakaiDOM|ForIF |
331 |
|
332 |
ElementTypeBinding: |
333 |
@Name: ClsISA |
334 |
@ElementType: |
335 |
dis:ISA |
336 |
@ShadowContent: |
337 |
@@ForCheck: ManakaiDOM|ForClass |
338 |
|
339 |
ElementTypeBinding: |
340 |
@Name: disDef |
341 |
@ElementType: |
342 |
dis:Def |
343 |
@ShadowContent: |
344 |
@@ContentType: |
345 |
lang:dis |
346 |
@@ForCheck: ManakaiDOM|ForClass |
347 |
|
348 |
ElementTypeBinding: |
349 |
@Name: Code |
350 |
@ElementType: |
351 |
dis:ResourceDef |
352 |
@ShadowContent: |
353 |
@@DISCore:resourceType: dlp|InlineCode |
354 |
@@ForCheck: ManakaiDOM|ForClass |
355 |
|
356 |
ElementTypeBinding: |
357 |
@Name: Test |
358 |
@ElementType: |
359 |
dis:ResourceDef |
360 |
@ShadowContent: |
361 |
@@DISCore:resourceType: test|StandaloneTest |
362 |
@@ForCheck: ManakaiDOM|ForClass |
363 |
|
364 |
ElementTypeBinding: |
365 |
@Name: TestC |
366 |
@ElementType: |
367 |
dis:ResourceDef |
368 |
@ShadowContent: |
369 |
@@DISCore:resourceType: test|StandaloneTest |
370 |
|
371 |
ResourceDef: |
372 |
@QName: Document |
373 |
@AliasFor: td|Document |
374 |
@For: ManakaiDOM|DOM |
375 |
|
376 |
ResourceDef: |
377 |
@QName: Element |
378 |
@AliasFor: te|Element |
379 |
@For: ManakaiDOM|DOM |
380 |
|
381 |
ResourceDef: |
382 |
@QName: Attr |
383 |
@AliasFor: te|Attr |
384 |
@For: ManakaiDOM|DOM |
385 |
|
386 |
ResourceDef: |
387 |
@QName: DOMString |
388 |
@AliasFor: DOMMain|DOMString |
389 |
@For: ManakaiDOM|DOM |
390 |
|
391 |
ResourceDef: |
392 |
@QName: DOMURI |
393 |
@AliasFor: ManakaiDOM|ManakaiDOMURI |
394 |
@For: ManakaiDOM|DOM3 |
395 |
|
396 |
ResourceDef: |
397 |
@QName: DOMTimeStamp |
398 |
@AliasFor: DOMMain|DOMTimeStamp |
399 |
@For: ManakaiDOM|DOM2 |
400 |
|
401 |
ResourceDef: |
402 |
@QName: boolean |
403 |
@AliasFor: idl|boolean||ManakaiDOM|all |
404 |
|
405 |
ResourceDef: |
406 |
@QName: Node |
407 |
@AliasFor: tc|Node |
408 |
@For: ManakaiDOM|ManakaiDOM |
409 |
|
410 |
ResourceDef: |
411 |
@QName: NodeList |
412 |
@AliasFor: tc|NodeList |
413 |
@For: ManakaiDOM|ManakaiDOM |
414 |
|
415 |
ResourceDef: |
416 |
@QName: StaticNodeList |
417 |
@AliasFor: tc|StaticNodeList |
418 |
@For: ManakaiDOM|ManakaiDOM |
419 |
|
420 |
ElementTypeBinding: |
421 |
@Name: enDesc |
422 |
@ElementType: |
423 |
dis:Description |
424 |
@ShadowContent: |
425 |
@@lang:en |
426 |
|
427 |
ElementTypeBinding: |
428 |
@Name: TrueCase |
429 |
@ElementType: |
430 |
dis:ResourceDef |
431 |
@ShadowContent: |
432 |
@@DISCore:resourceType: |
433 |
ManakaiDOM:InCase |
434 |
@@Value: |
435 |
@@@@: 1 |
436 |
@@@ContentType: DISCore|Boolean |
437 |
@@Type: idl|boolean||ManakaiDOM|all |
438 |
|
439 |
ElementTypeBinding: |
440 |
@Name: FalseCase |
441 |
@ElementType: |
442 |
dis:ResourceDef |
443 |
@ShadowContent: |
444 |
@@DISCore:resourceType: |
445 |
ManakaiDOM:InCase |
446 |
@@Value: |
447 |
@@@@: 0 |
448 |
@@@ContentType: DISCore|Boolean |
449 |
@@Type: idl|boolean||ManakaiDOM|all |
450 |
|
451 |
## -- Features |
452 |
|
453 |
ElementTypeBinding: |
454 |
@Name: FeatureDef |
455 |
@ElementType: |
456 |
dis:ResourceDef |
457 |
@ShadowContent: |
458 |
@@DISCore:resourceType: f|Feature |
459 |
@@For: =ManakaiDOM|all |
460 |
|
461 |
ElementTypeBinding: |
462 |
@Name: FeatureVerDef |
463 |
@ElementType: |
464 |
dis:ResourceDef |
465 |
@ShadowContent: |
466 |
@@DISCore:resourceType: f|Feature |
467 |
|
468 |
ElementTypeBinding: |
469 |
@Name: featureQName |
470 |
@ElementType: |
471 |
f:name |
472 |
@ShadowContent: |
473 |
@@ContentType: DISCore|QName |
474 |
|
475 |
FeatureDef: |
476 |
@featureQName: fe|H2H |
477 |
@QName: H2HFeature |
478 |
@FeatureVerDef: |
479 |
@@QName: H2HFeature10 |
480 |
@@Version: 1.0 |
481 |
@@f:instanceOf: H2HFeature |
482 |
@@f:requires: tx|XMLFeature30 |
483 |
@@enDesc: |
484 |
The H2H Document Markup Language DOM, version 1.0. |
485 |
|
486 |
## -- Implementation |
487 |
|
488 |
## TODO: |
489 |
|
490 |
## -- Elements |
491 |
|
492 |
IFClsDef: |
493 |
@IFQName: H2HElement |
494 |
@ClsQName: ManakaiH2HElement |
495 |
|
496 |
@IFISA: Element |
497 |
@ClsISA: te|ManakaiDOMElement |
498 |
|
499 |
@s:elementType: AnyH2HElement||ManakaiDOM|all |
500 |
##H2HElement |
501 |
|
502 |
ResourceDef: |
503 |
@QName: AnyH2HElement |
504 |
@DISCore:resourceType: s|AnyElementInNS |
505 |
@AppName: |
506 |
@@@: h2h|* |
507 |
@@ContentType: DISCore|QName |
508 |
@ForCheck: =ManakaiDOM|all |
509 |
|
510 |
ElementTypeBinding: |
511 |
@Name: NodeReadOnlyError |
512 |
@ElementType: |
513 |
dx:raises |
514 |
@ShadowContent: |
515 |
@@@: MDOMX|NOMOD_THIS |
516 |
@@Description: |
517 |
@@@lang:en |
518 |
@@@@: |
519 |
If the node or a descendant of it, which |
520 |
is to be modified, is read-only. |
521 |
|
522 |
## -- Parser |
523 |
|
524 |
IFClsDef: |
525 |
@IFQName: H2HParser |
526 |
@ClsQName: ManakaiH2HParser |
527 |
|
528 |
@Implement: ecore|MUErrorTarget||ManakaiDOM|Perl |
529 |
|
530 |
@DISLang:role: gls|ParserRole |
531 |
|
532 |
@f:implements: H2HFeature10 |
533 |
@f:provides: |
534 |
@@@: H2HFeature10 |
535 |
@@f:through: c|ManakaiDOMImplementation |
536 |
|
537 |
@enDesc: |
538 |
A <IF::H2HParser> object parses an H2H/0.9 or H2H/1.0 |
539 |
textual document and returns it as an object. |
540 |
|
541 |
@Attr: |
542 |
@@Name: domConfig |
543 |
@@enDesc: |
544 |
The configuration of the parser. |
545 |
|
546 |
@@Get: |
547 |
@@@Type: c|DOMConfiguration |
548 |
@@@enDesc: The DOM configuration object. |
549 |
@@@PerlDef: |
550 |
__CODE{c|getConfigObject:: |
551 |
$target => $self, |
552 |
$targetHash => $self, |
553 |
$targetType => {<IFName::H2HParser>}, |
554 |
$result => $r, |
555 |
}__; |
556 |
|
557 |
@Method: |
558 |
@@ManakaiDOM:isForInternal:1 |
559 |
@@ForCheck: ManakaiDOM|ForClass |
560 |
@@Operator: DISPerl|NewMethod |
561 |
@@enDesc: |
562 |
Creates a new instance of the object. |
563 |
@@Param: |
564 |
@@@Name: impl |
565 |
@@@Type: gls|GLSImplementation |
566 |
@@@enDesc: |
567 |
The implementation from which the parser is created. |
568 |
@@Param: |
569 |
@@@Name: features |
570 |
@@@Type: DOMString |
571 |
@@@dis:actualType: f|FeaturesString |
572 |
@@@enDesc: |
573 |
The set of features requested for the parser. |
574 |
@@Return: |
575 |
@@@Type: DOMMain|DOMObject |
576 |
@@@enDesc: |
577 |
The newly created parser. |
578 |
@@@PerlDef: |
579 |
$r = bless { |
580 |
<H::f|implementation> => $impl->get_feature ('XML' => '3.0'), |
581 |
}, $self; |
582 |
|
583 |
@Method: |
584 |
@@Name: parseString |
585 |
@@enDesc: |
586 |
Parses a string as SWDML textual document and converts it into |
587 |
DOM tree. |
588 |
@@Param: |
589 |
@@@Name: sourceText |
590 |
@@@Type: DOMString |
591 |
@@@enDesc: |
592 |
The text to parse. |
593 |
@@Return: |
594 |
@@@Type: DISPerl|HASH |
595 |
@@@enDesc: |
596 |
An object representation of <P::sourceText>. |
597 |
@@@PerlDef: |
598 |
$self->{token} = []; |
599 |
$sourceText =~ s/\x0D\x0A/\x0A/g; |
600 |
$sourceText =~ tr/\x0D/\x0A/; |
601 |
$self->{line} = [split /\x0A/, $sourceText]; |
602 |
$self->{location} = {}; |
603 |
$self->{doc} = $self->{<H::f|implementation>} |
604 |
->create_document (<Q::html5|>, 'html'); |
605 |
$self->{doc}->strict_error_checking (false); |
606 |
$self->{doc}->document_element |
607 |
->set_attribute_ns (<Q::xmlns|>, 'xmlns', <Q::html5|>); |
608 |
__DEEP{ |
609 |
$self->_construct_tree; |
610 |
}__; |
611 |
|
612 |
$r = $self->{doc}; |
613 |
|
614 |
@Method: |
615 |
@@Name: shiftLine |
616 |
@@ManakaiDOM:isForInternal:1 |
617 |
@@ForCheck: ManakaiDOM|ForClass |
618 |
@@enDesc: |
619 |
Returns the next character. |
620 |
@@Return: |
621 |
@@@Type: DOMString |
622 |
@@@enDesc: |
623 |
A line, without line break characters. |
624 |
@@@nullCase: |
625 |
@@@@enDesc: |
626 |
If no more line is available. |
627 |
@@@PerlDef: |
628 |
if (@{$self->{line}}) { |
629 |
$r = shift @{$self->{line}}; |
630 |
} else { |
631 |
$r = null; |
632 |
} |
633 |
|
634 |
@Method: |
635 |
@@Name: shiftToken |
636 |
@@ManakaiDOM:isForInternal: 1 |
637 |
@@Return: |
638 |
@@@Type: dlp|HASH||ManakaiDOM|all |
639 |
@@@PerlDef: |
640 |
if (@{$self->{token}}) { |
641 |
$r = shift @{$self->{token}}; |
642 |
} else { |
643 |
my $attrvalue = sub { |
644 |
my $v = shift; |
645 |
$v =~ s/"/"/g; |
646 |
$v =~ s/</</g; |
647 |
$v =~ s/>/>/g; |
648 |
$v =~ s/®/\x{00AE}/g; |
649 |
$v =~ s/♥/\x{2661}/g; |
650 |
$v =~ s/&/&/g; |
651 |
$v; |
652 |
}; |
653 |
my $uriv = sub { |
654 |
my $v = $attrvalue->(shift); |
655 |
$v =~ s/^\{/(/; |
656 |
$v =~ s/\}$/)/; |
657 |
$v =~ s/^\#([0-9si]+)$/($1)/; |
658 |
$v =~ s/^\(([0-9]{4})([0-9]{2})([0-9]{2})([^)]*)\)$/($1, $2, $3$4)/; |
659 |
$v =~ s/[si]/, /g if $v =~ /^\(/ and $v =~ /\)$/; |
660 |
$v; |
661 |
}; |
662 |
|
663 |
$r = {type => '#EOF'}; |
664 |
L: while (defined (my $line = $self->_shift_line)) { |
665 |
if ($line =~ s/^([A-Z]+|T[0-9])(\*?\+?\*?)(?:\s+|$)//) { |
666 |
my $command = $1; |
667 |
my $flag = $2; |
668 |
$r = {type => 'start', value => $command}; |
669 |
|
670 |
my $uri; |
671 |
if ($flag =~ /\*/ and $line =~ s/^([^{\s]\S*)\s*//) { |
672 |
$uri = $1; |
673 |
} |
674 |
|
675 |
my $attr = ''; |
676 |
if ($line =~ s/^\{(\s*(?:[A-Za-z][^{}]*)?)\}\s*//) { |
677 |
$attr = $1; |
678 |
} |
679 |
|
680 |
if (not defined $uri and |
681 |
$flag =~ /\*/ and $line =~ s/^([^{\s]\S*)\s*//) { |
682 |
$uri = $1; |
683 |
} |
684 |
|
685 |
my @token; |
686 |
my $info = { |
687 |
# val# val#(*) |
688 |
ABBR => [2, 2], |
689 |
ACRONYM => [2, 2], |
690 |
CITE => [2, 1], |
691 |
LDIARY => [4, 4], |
692 |
LIMG => [4, 4], |
693 |
LINK => [2, 1], |
694 |
LMG => [2, 2], |
695 |
LNEW => [2, 2], |
696 |
PERSON => [2, 2], |
697 |
RIBU => [2, 2], |
698 |
RUBY => [2, 2], |
699 |
SEE => [2, 2], |
700 |
}->{$command}; |
701 |
my @value = split /\s+/, $line, |
702 |
($flag =~ /\*/ ? $info->[1] : $info->[0]) || 1; |
703 |
|
704 |
if (defined $uri) { |
705 |
push @token, {type => 'uri', value => $uriv->($uri)}; |
706 |
} |
707 |
|
708 |
my %attr; |
709 |
while ($attr =~ /([A-Za-z0-9_-]+)\s*(?:=>?|:)\s*([^";,]+|"[^"]+")/gc) { |
710 |
my $name = lc $1; |
711 |
my $value = $2; |
712 |
$value =~ tr/"//d; |
713 |
$attr{$name} = $value; |
714 |
} |
715 |
delete $attr{'content-type'}; |
716 |
|
717 |
if ({ |
718 |
ABBR => true, ACRONYM => true, |
719 |
RUBY => true, RIBU => true, |
720 |
}->{$command}) { |
721 |
if (@value == 1 and $attr{title}) { |
722 |
push @value, $attr{title}; |
723 |
delete $attr{title}; |
724 |
} |
725 |
if (@value == 2) { |
726 |
unshift @{$self->{line}}, 'RB', |
727 |
'DATA {} >>'.$value[1], |
728 |
'/RB', |
729 |
'RT', |
730 |
'DATA {} >>'.$value[0], |
731 |
'/RT', |
732 |
'/'.$command; |
733 |
} else { |
734 |
unshift @{$self->{line}}, 'DATA {} >>'.$value[0], '/'.$command; |
735 |
} |
736 |
} elsif ($command eq 'CITE') { |
737 |
if (@value == 2) { |
738 |
if (defined $uri or $value[0] !~ /^[a-z-]+:/) { |
739 |
unshift @{$self->{line}}, 'SRC', |
740 |
'DATA {} >>'.$value[0].' '.$value[1], |
741 |
'/SRC', 'BODYTEXT'; |
742 |
} else { |
743 |
push @token, {type => 'uri', value => $uriv->($value[0])}; |
744 |
unshift @{$self->{line}}, 'SRC', |
745 |
'DATA {} >>'.$value[1], |
746 |
'/SRC', 'BODYTEXT'; |
747 |
} |
748 |
} elsif (@value == 1) { |
749 |
if (defined $uri or $value[0] !~ /^[a-z-]+:/) { |
750 |
unshift @{$self->{line}}, 'SRC', |
751 |
'DATA {} >>'.$value[0], |
752 |
'/SRC', 'BODYTEXT'; |
753 |
} else { |
754 |
push @token, {type => 'uri', value => $uriv->($value[0])}; |
755 |
unshift @{$self->{line}}, 'BODYTEXT'; |
756 |
} |
757 |
} else { |
758 |
unshift @{$self->{line}}, 'BODYTEXT'; |
759 |
} |
760 |
} elsif ($command eq 'DATA') { |
761 |
my @token; |
762 |
$line =~ s/^>>//; |
763 |
while (length $line) { |
764 |
if ($line =~ s/^<([a-z0-9]+)\s*//) { |
765 |
my $tagname = $1; |
766 |
push @token, {type => 'start', value => $tagname}; |
767 |
while ($line =~ s/^([a-z-]+)\s*=\s*"([^"]*)"\s*//) { |
768 |
push @token, {type => $1, value => $attrvalue->($2)}; |
769 |
} |
770 |
$line =~ s#^/?\s*>##; |
771 |
push @token, {type => 'end', value => $tagname} |
772 |
if $tagname eq 'img' or $tagname eq 'input' or |
773 |
$tagname eq 'br'; |
774 |
} elsif ($line =~ s#^</([a-z0-9]+)\s*>##) { |
775 |
push @token, {type => 'end', value => $1}; |
776 |
} elsif ($line =~ s/^<!--(.*?)-->//) { |
777 |
push @token, {type => 'html-comment', value => $1}; |
778 |
} elsif ($line =~ s/^&([a-z]+);//) { |
779 |
my $name = $1; |
780 |
if ($name eq 'amp') { |
781 |
push @token, {type => 'text', value => '&'}; |
782 |
} elsif ($name eq 'lt') { |
783 |
push @token, {type => 'text', value => '<'}; |
784 |
} elsif ($name eq 'gt') { |
785 |
push @token, {type => 'text', value => '>'}; |
786 |
} elsif ($name eq 'quot') { |
787 |
push @token, {type => 'text', value => '"'}; |
788 |
} elsif ($name eq 'reg') { |
789 |
push @token, {type => 'text', value => "\x{00AE}"}; |
790 |
} elsif ($name eq 'amp') { |
791 |
push @token, {type => 'text', value => "\x{2661}"}; |
792 |
} else { |
793 |
push @token, {type => 'char', value => $name}; |
794 |
} |
795 |
} elsif ($line =~ s/^&#([0-9]+);//) { |
796 |
push @token, {type => 'text', value => ord $1}; |
797 |
} elsif ($line =~ s/^&#x([0-9A-Fa-f]+);//) { |
798 |
push @token, {type => 'text', value => ord hex $1}; |
799 |
} elsif ($line =~ s/^([^<&]+)//) { |
800 |
push @token, {type => 'text', value => $1}; |
801 |
} else { |
802 |
push @token, {type => 'text', value => substr ($line, 0, 1)}; |
803 |
substr ($line, 0, 1) = ''; |
804 |
} |
805 |
} |
806 |
push @token, {type => 'eol'}; |
807 |
|
808 |
$r = shift @token; |
809 |
push @{$self->{token}}, @token; |
810 |
last L; |
811 |
} elsif ({ |
812 |
DD => true, DT => true, |
813 |
DEL => true, INS => true, |
814 |
LI => true, |
815 |
RB => true, RT => true, |
816 |
STRONG => true, |
817 |
YAMI => true, |
818 |
EM => true, |
819 |
HOUR => true, KION => true, LUNCH => true, |
820 |
TAION => true, TENKI => true, THEME => true, |
821 |
T1 => true, T2 => true, T3 => true, T4 => true, |
822 |
T5 => true, T6 => true, T7 => true, SP => true, |
823 |
}->{$command}) { |
824 |
if (@value) { |
825 |
unshift @{$self->{line}}, 'DATA {} >>'.$value[0], '/'.$command; |
826 |
} |
827 |
} elsif ($command eq 'DIV') { |
828 |
if (@value) { |
829 |
$r = {type => 'class', value => $value[0]}; |
830 |
} |
831 |
} elsif ($command eq 'LDIARY') { |
832 |
$value[0] =~ s/^([0-9]{4})([0-9]{2})([0-9]{2})/$1, $2, $3/; |
833 |
$value[0] =~ s/[is]/, /; |
834 |
$r = {type => 'start', value => 'LINK'}; |
835 |
push @token, {type => 'uri', value => "($value[0])"}; |
836 |
unshift @{$self->{line}}, 'DATA {} >>'.$value[1], '/LINK'; |
837 |
} elsif ($command eq 'LIMG') { |
838 |
$r = {type => 'start', value => 'IMG'}; |
839 |
push @token, {type => 'uri', value => $uriv->($value[0])}; |
840 |
unshift @{$self->{line}}, 'DATA {} >>'.$value[3], '/IMG'; |
841 |
} elsif ($command eq 'LMG') { |
842 |
$r = {type => 'start', value => 'IMG'}; |
843 |
push @token, {type => 'uri', value => $uriv->($value[0])}; |
844 |
unshift @{$self->{line}}, 'DATA {} >>'.$value[1], '/IMG'; |
845 |
} elsif ($command eq 'LINK') { |
846 |
if (@value == 2) { |
847 |
push @token, {type => 'uri', value => $uriv->($value[0])}; |
848 |
unshift @{$self->{line}}, 'DATA {} >>'.$value[1], '/LINK'; |
849 |
} elsif ($flag =~ /\+/) { |
850 |
push @token, {type => 'uri', value => $uriv->($value[0])}; |
851 |
} else { |
852 |
unshift @{$self->{line}}, 'DATA {} >>'.$value[0], '/LINK'; |
853 |
} |
854 |
} elsif ($command eq 'NEW') { |
855 |
$r = {type => 'start', value => 'SECTION'}; |
856 |
unshift @{$self->{line}}, 'H', 'DATA {} >>'.$value[0], '/H'; |
857 |
} elsif ($command eq 'LNEW') { |
858 |
$r = {type => 'start', value => 'SECTION'}; |
859 |
push @token, {type => 'uri', value => $uriv->($value[0])}; |
860 |
unshift @{$self->{line}}, 'H', 'DATA {} >>'.$value[1], '/H'; |
861 |
} elsif ($command eq 'SUB') { |
862 |
$r = {type => 'start', value => 'SUB'}; |
863 |
unshift @{$self->{line}}, 'H', 'DATA {} >>'.$value[0], '/H'; |
864 |
} elsif ($command eq 'PERSON') { |
865 |
push @token, {type => 'key', value => $attrvalue->($value[0])}; |
866 |
unshift @{$self->{line}}, 'DATA {} >>'.$value[1], '/PERSON'; |
867 |
} elsif ($command eq 'SEE') { |
868 |
if (@value == 2) { |
869 |
push @token, {type => 'key', value => $attrvalue->($value[0])}; |
870 |
unshift @{$self->{line}}, 'DATA {} >>'.$value[1], '/SEE'; |
871 |
} else { |
872 |
unshift @{$self->{line}}, 'DATA {} >>'.$value[0], '/SEE'; |
873 |
} |
874 |
} elsif ($command eq 'SPAN') { |
875 |
if (@value == 2) { |
876 |
push @token, {type => 'class', |
877 |
value => $attrvalue->($value[0])}; |
878 |
unshift @{$self->{line}}, 'DATA {} >>'.$value[1], '/SPAN'; |
879 |
} else { |
880 |
unshift @{$self->{line}}, 'DATA {} >>'.$value[0], '/SPAN'; |
881 |
} |
882 |
} elsif ($command eq 'OK') { |
883 |
$r = {type => '#EOF'}; |
884 |
next L; |
885 |
} elsif ($command eq 'XML') { |
886 |
unshift @{$self->{line}}, 'DATA {} >>XML '.$line; |
887 |
next L; |
888 |
} |
889 |
|
890 |
for (keys %attr) { |
891 |
push @token, {type => $_, value => $attrvalue->($attr{$_})}; |
892 |
} |
893 |
|
894 |
push @{$self->{token}}, @token; |
895 |
last L; |
896 |
} elsif ($line eq 'H2H/1.0') { |
897 |
$r = {type => 'magic', value => 'H2H/1.0'}; |
898 |
last L; |
899 |
} elsif ($line =~ m#^/([A-Z]+)\s*$#) { |
900 |
$r = {type => 'end', value => $1}; |
901 |
last L; |
902 |
} elsif ($line =~ s/^!#//) { |
903 |
$r = {type => 'hnf-comment', value => $line}; |
904 |
last L; |
905 |
} elsif ($line =~ s/^!//) { |
906 |
$r = {type => 'html-comment', value => $line}; |
907 |
last L; |
908 |
} else { |
909 |
unshift @{$self->{line}}, 'DATA {} >>'.$line; |
910 |
next L; |
911 |
} |
912 |
} # L |
913 |
} |
914 |
|
915 |
@Method: |
916 |
@@Name: constructTree |
917 |
@@ManakaiDOM:isForInternal: 1 |
918 |
@@Return: |
919 |
@@@PerlDef: |
920 |
my $doc_el = $self->{doc}->document_element; |
921 |
my $head_el = $self->{doc}->create_element_ns (<Q::html5|>, 'head'); |
922 |
my $body_el = $self->{doc}->create_element_ns (<Q::html5|>, 'body'); |
923 |
$doc_el->append_child ($head_el); |
924 |
$doc_el->append_child ($body_el); |
925 |
$doc_el->set_user_data ('command-name' => '#html'); |
926 |
$head_el->set_user_data ('command-name' => '#head'); |
927 |
$body_el->set_user_data ('command-name' => '#body'); |
928 |
$doc_el->set_attribute_ns (<Q::sw09|>, 'sw9:Name' => 'H2H'); |
929 |
$doc_el->set_attribute_ns (<Q::sw09|>, 'sw9:Version' => '0.9'); |
930 |
|
931 |
my $parent = { |
932 |
subsection => $body_el, |
933 |
attr => $body_el, |
934 |
text => $body_el, |
935 |
}; |
936 |
my $state = 'data'; |
937 |
## data - normal |
938 |
## list - UL or OL |
939 |
## br - after br start tag token |
940 |
## eol - after eol token |
941 |
|
942 |
T: while (my $token = $self->_shift_token) { |
943 |
last T if $token->{type} eq '#EOF'; |
944 |
|
945 |
if ($token->{type} eq 'text') { |
946 |
if ($state eq 'list') { |
947 |
my $li_el = $self->{doc}->create_element_ns (<Q::html5|>, 'li'); |
948 |
$li_el->manakai_append_text ($token->{value}); |
949 |
$parent->{text}->append_child ($li_el); |
950 |
} else { |
951 |
$parent->{text}->manakai_append_text ("\x0A") if $state eq 'eol'; |
952 |
$parent->{text}->manakai_append_text ($token->{value}); |
953 |
$state = 'data'; |
954 |
} |
955 |
} elsif ($token->{type} eq 'eol') { |
956 |
if ($state eq 'eol') { |
957 |
$parent->{text}->manakai_append_text ("\x0A"); |
958 |
} else { |
959 |
$state = $state eq 'br' ? 'data' : 'eol'; |
960 |
} |
961 |
} elsif ($token->{type} eq 'start') { |
962 |
my $info = { |
963 |
# nsuri, qname, parent, state |
964 |
ABBR => [<Q::html5|>, 'abbr', $parent->{text}, 'data'], |
965 |
ACRONYM => [<Q::html5|>, 'abbr', $parent->{text}, 'data'], |
966 |
BODYTEXT => [<Q::html3|>, 'bodytext', $parent->{text}, 'data'], |
967 |
CITE => [<Q::html5|>, 'blockquote', $parent->{text}, 'data', |
968 |
{PRE => true}], |
969 |
DD => [<Q::html5|>, 'dd', $parent->{text}, 'data'], |
970 |
DEL => [<Q::html5|>, 'del', $parent->{text}, 'data'], |
971 |
DIV => [<Q::html5|>, 'div', $parent->{text}, 'data', {P => true}], |
972 |
DL => [<Q::html5|>, 'dl', $parent->{text}, 'data'], |
973 |
DT => [<Q::html5|>, 'dt', $parent->{text}, 'data'], |
974 |
EM => [<Q::html5|>, 'em', $parent->{text}, 'data'], |
975 |
FN => [<Q::h2h|>, 'fn', $parent->{text}, 'data'], |
976 |
H => [<Q::xhtml2|>, 'h', $parent->{text}, 'data'], |
977 |
HOUR => [<Q::h2h|>, 'hour', $head_el, 'data'], |
978 |
IMG => [<Q::html5|>, 'img', $parent->{text}, 'data'], |
979 |
INS => [<Q::html5|>, 'ins', $parent->{text}, 'data'], |
980 |
KION => [<Q::h2h|>, 'kion', $head_el, 'data'], |
981 |
LI => [<Q::html5|>, 'li', $parent->{text}, 'data'], |
982 |
LINK => [<Q::html5|>, 'a', $parent->{text}, 'data'], |
983 |
LUNCH => [<Q::h2h|>, 'lunch', $head_el, 'data'], |
984 |
OL => [<Q::html5|>, 'ol', $parent->{text}, 'list', {PRE => true}], |
985 |
P => [<Q::html5|>, 'p', $parent->{text}, 'data', |
986 |
{P => true, PRE => true}], |
987 |
PERSON => [<Q::html3|>, 'person', $parent->{text}, 'data'], |
988 |
PRE => [<Q::html5|>, 'pre', $parent->{text}, 'data', |
989 |
{P => true}], |
990 |
RB => [<Q::html5|>, 'rb', $parent->{text}, 'data'], |
991 |
RIBU => [<Q::html5|>, 'ruby', $parent->{text}, 'data'], |
992 |
RT => [<Q::html5|>, 'rt', $parent->{text}, 'data'], |
993 |
RUBY => [<Q::html5|>, 'ruby', $parent->{text}, 'data'], |
994 |
SECTION => [<Q::html5|>, 'section', $body_el, 'data'], |
995 |
SEE => [<Q::html5|>, 'i', $parent->{text}, 'data'], |
996 |
SP => [<Q::h2h|>, 'sp', $head_el, 'data'], |
997 |
SPAN => [<Q::html5|>, 'span', $parent->{text}, 'data'], |
998 |
SRC => [<Q::html3|>, 'credit', $parent->{text}, 'data'], |
999 |
STRONG => [<Q::html5|>, 'strong', $parent->{text}, 'data'], |
1000 |
SUBSECTION => [<Q::html5|>, 'section', $parent->{subsection}, 'data'], |
1001 |
T1 => [<Q::h2h|>, 't1', $head_el, 'data'], |
1002 |
T2 => [<Q::h2h|>, 't2', $head_el, 'data'], |
1003 |
T3 => [<Q::h2h|>, 't3', $head_el, 'data'], |
1004 |
T4 => [<Q::h2h|>, 't4', $head_el, 'data'], |
1005 |
T5 => [<Q::h2h|>, 't5', $head_el, 'data'], |
1006 |
T6 => [<Q::h2h|>, 't6', $head_el, 'data'], |
1007 |
T7 => [<Q::h2h|>, 't7', $head_el, 'data'], |
1008 |
TAION => [<Q::h2h|>, 'taion', $head_el, 'data'], |
1009 |
TENKI => [<Q::h2h|>, 'tenki', $head_el, 'data'], |
1010 |
THEME => [<Q::h2h|>, 'theme', $head_el, 'data'], |
1011 |
UL => [<Q::html5|>, 'ul', $parent->{text}, 'list', {PRE => true}], |
1012 |
YAMI => [<Q::h2h|>, 'yami', $parent->{text}, 'data'], |
1013 |
a => [<Q::html5|>, 'a', $parent->{text}, 'data'], |
1014 |
abbr => [<Q::html5|>, 'abbr', $parent->{text}, 'data'], |
1015 |
acronym => [<Q::html5|>, 'abbr', $parent->{text}, 'data'], |
1016 |
blockquote => [<Q::html5|>, 'blockquote', $parent->{text}, 'data'], |
1017 |
br => [<Q::html5|>, 'br', $parent->{text}, 'br'], |
1018 |
caption => [<Q::html5|>, 'caption', $parent->{text}, 'data'], |
1019 |
code => [<Q::html5|>, 'code', $parent->{text}, 'data'], |
1020 |
dd => [<Q::html5|>, 'dd', $parent->{text}, 'data'], |
1021 |
del => [<Q::html5|>, 'del', $parent->{text}, 'data'], |
1022 |
dfn => [<Q::html5|>, 'dfn', $parent->{text}, 'data'], |
1023 |
div => [<Q::html5|>, 'div', $parent->{text}, 'data'], |
1024 |
dl => [<Q::html5|>, 'dl', $parent->{text}, 'data'], |
1025 |
dt => [<Q::html5|>, 'dt', $parent->{text}, 'data'], |
1026 |
em => [<Q::html5|>, 'em', $parent->{text}, 'data'], |
1027 |
form => [<Q::html5|>, 'form', $parent->{text}, 'data'], |
1028 |
h1 => [<Q::html5|>, 'h1', $parent->{text}, 'data'], |
1029 |
h2 => [<Q::html5|>, 'h2', $parent->{text}, 'data'], |
1030 |
h3 => [<Q::html5|>, 'h3', $parent->{text}, 'data'], |
1031 |
h4 => [<Q::html5|>, 'h4', $parent->{text}, 'data'], |
1032 |
img => [<Q::html5|>, 'img', $parent->{text}, 'data'], |
1033 |
input => [<Q::html5|>, 'input', $parent->{text}, 'data'], |
1034 |
ins => [<Q::html5|>, 'ins', $parent->{text}, 'data'], |
1035 |
kbd => [<Q::html5|>, 'kbd', $parent->{text}, 'data'], |
1036 |
label => [<Q::html5|>, 'label', $parent->{text}, 'data'], |
1037 |
li => [<Q::html5|>, 'li', $parent->{text}, 'data'], |
1038 |
ol => [<Q::html5|>, 'ol', $parent->{text}, 'data'], |
1039 |
p => [<Q::html5|>, 'p', $parent->{text}, 'data'], |
1040 |
pre => [<Q::html5|>, 'pre', $parent->{text}, 'data'], |
1041 |
q => [<Q::html5|>, 'q', $parent->{text}, 'data'], |
1042 |
rb => [<Q::html5|>, 'rb', $parent->{text}, 'data'], |
1043 |
rp => [<Q::html5|>, 'rp', $parent->{text}, 'data'], |
1044 |
rt => [<Q::html5|>, 'rt', $parent->{text}, 'data'], |
1045 |
ruby => [<Q::html5|>, 'ruby', $parent->{text}, 'data'], |
1046 |
span => [<Q::html5|>, 'span', $parent->{text}, 'data'], |
1047 |
strong => [<Q::html5|>, 'strong', $parent->{text}, 'data'], |
1048 |
sup => [<Q::html5|>, 'sup', $parent->{text}, 'data'], |
1049 |
table => [<Q::html5|>, 'table', $parent->{text}, 'data'], |
1050 |
tbody => [<Q::html5|>, 'tbody', $parent->{text}, 'data'], |
1051 |
td => [<Q::html5|>, 'td', $parent->{text}, 'data'], |
1052 |
th => [<Q::html5|>, 'th', $parent->{text}, 'data'], |
1053 |
thead => [<Q::html5|>, 'thead', $parent->{text}, 'data'], |
1054 |
tr => [<Q::html5|>, 'tr', $parent->{text}, 'data'], |
1055 |
ul => [<Q::html5|>, 'ul', $parent->{text}, 'data'], |
1056 |
var => [<Q::html5|>, 'var', $parent->{text}, 'data'], |
1057 |
}->{$token->{value}} |
1058 |
|| [<Q::h2h|>, $token->{value}, $parent->{text}, 'data']; |
1059 |
while ($info->[4]->{$info->[2]->get_user_data ('command-name')}) { |
1060 |
$info->[2] = $info->[2]->parent_node; |
1061 |
} |
1062 |
my $el = $self->{doc}->create_element_ns ($info->[0], $info->[1]); |
1063 |
$el->set_user_data ('command-name', $token->{value}); |
1064 |
$info->[2]->append_child ($el); |
1065 |
$parent->{text} = $el; |
1066 |
$parent->{attr} = $el; |
1067 |
$parent->{subsection} = $el if $token->{value} eq 'SECTION'; |
1068 |
$state = $info->[3]; |
1069 |
} elsif ($token->{type} eq 'end') { |
1070 |
E: while (my $et = $parent->{text}->get_user_data ('command-name')) { |
1071 |
$parent->{text} = $parent->{text}->parent_node; |
1072 |
last E if $et eq $token->{value}; |
1073 |
last E if $et eq '#body'; |
1074 |
} |
1075 |
$parent->{attr} = $parent->{text}; |
1076 |
$state = { |
1077 |
UL => 'list', |
1078 |
OL => 'list', |
1079 |
}->{$parent->{text}->get_user_data ('command-name')} |
1080 |
|| $state eq 'br' ? 'br' : 'data'; |
1081 |
} elsif ($token->{type} eq 'char') { |
1082 |
my $el = $self->{doc}->create_element_ns (<Q::h2h|>, 'char'); |
1083 |
$el->manakai_append_text ($token->{value}); |
1084 |
$parent->{text}->append_child ($el); |
1085 |
$state = 'data' if $state eq 'br'; |
1086 |
} elsif ($token->{type} eq 'magic') { |
1087 |
my ($name, $version) = split m#/#, $token->{value}, 2; |
1088 |
$doc_el->set_attribute_ns (<Q::sw09|>, 'sw9:Name', $name); |
1089 |
$doc_el->set_attribute_ns (<Q::sw09|>, 'sw9:Version', $version); |
1090 |
} elsif ($token->{type} eq 'hnf-comment') { |
1091 |
my $com = $self->{doc}->create_element_ns |
1092 |
(<Q::h2h|>, 'hnf-comment'); |
1093 |
$com->text_content ($token->{value}); |
1094 |
$parent->{text}->append_child ($com); |
1095 |
} elsif ($token->{type} eq 'html-comment') { |
1096 |
my $com = $self->{doc}->create_element_ns |
1097 |
(<Q::h2h|>, 'html-comment'); |
1098 |
$com->text_content ($token->{value}); |
1099 |
$parent->{text}->append_child ($com); |
1100 |
} elsif ($token->{type} eq 'source') { |
1101 |
my $src = $self->{doc}->create_element_ns (<Q::html3|>, 'credit'); |
1102 |
$src->manakai_append_text ($token->{value}); |
1103 |
$parent->{text}->append_child ($src); |
1104 |
} elsif ($token->{type} eq 'uri') { |
1105 |
my $v = $token->{value}; |
1106 |
if ($v =~ /^\(([^()]+)\)$/) { |
1107 |
my @v = split /\s*,\s*/, $1; |
1108 |
$parent->{attr}->set_attribute_ns |
1109 |
(<Q::h2h|>, 'href-year' => $v[0]+0); |
1110 |
$parent->{attr}->set_attribute_ns |
1111 |
(<Q::h2h|>, 'href-month' => $v[1]+0); |
1112 |
$parent->{attr}->set_attribute_ns |
1113 |
(<Q::h2h|>, 'href-day' => $v[2]+0); |
1114 |
$parent->{attr}->set_attribute_ns |
1115 |
(<Q::h2h|>, 'href-section' => $v[3]+0) if $v[3]; |
1116 |
$parent->{attr}->set_attribute_ns |
1117 |
(<Q::h2h|>, 'href-subsection' => $v[4]+0) |
1118 |
if $v[4]; |
1119 |
} else { |
1120 |
my $xuri = $parent->{attr}->manakai_expanded_uri; |
1121 |
if ($xuri eq <Q::html5|a>) { |
1122 |
$parent->{attr}->set_attribute_ns |
1123 |
(null, href => $token->{value}); |
1124 |
} elsif ($xuri eq <Q::html5|blockquote>) { |
1125 |
$parent->{attr}->set_attribute_ns |
1126 |
(null, cite => $token->{value}); |
1127 |
} else { |
1128 |
$parent->{attr}->set_attribute_ns |
1129 |
(<Q::xhtml2|>, href => $token->{value}); |
1130 |
} |
1131 |
} |
1132 |
} elsif ({ |
1133 |
title => true, style => true, |
1134 |
class => true, href => true, 'accept-charset' => true, |
1135 |
action => true, method => true, alt => true, src => true, |
1136 |
type => true, value => true, name => true, accesskey => true, |
1137 |
for => true, cite => true, onclick => true, colspan => true, |
1138 |
scope => true, summary => true, |
1139 |
}->{$token->{type}}) { |
1140 |
$parent->{attr}->set_attribute_ns |
1141 |
(null, $token->{type}, $token->{value}); |
1142 |
} elsif ($token->{type} eq 'cat') { |
1143 |
for (split /\s*,\s*/, $token->{value}) { |
1144 |
my $el = $self->{doc}->create_element_ns (<Q::h2h|>, 'cat'); |
1145 |
$el->manakai_append_text ($_); |
1146 |
$parent->{attr}->append_child ($el); |
1147 |
} |
1148 |
} elsif ($token->{type} eq 'lang' or $token->{type} eq 'xml:lang') { |
1149 |
$parent->{attr}->set_attribute_ns |
1150 |
(<Q::xml|>, 'xml:lang' => $token->{value}); |
1151 |
} elsif ($token->{type} eq 'id') { |
1152 |
$parent->{attr}->set_attribute_ns |
1153 |
(<Q::xml|>, 'xml:id' => $token->{value}); |
1154 |
} elsif ($token->{type} eq 'wbradded') { |
1155 |
# ignore |
1156 |
} else { |
1157 |
# key, level, place, position, time |
1158 |
$parent->{attr}->set_attribute_ns |
1159 |
(<Q::h2h|>, $token->{type}, $token->{value}); |
1160 |
} |
1161 |
} |
1162 |
|
1163 |
@Method: |
1164 |
@@ManakaiDOM:isForInternal: 1 |
1165 |
@@Operator: ManakaiDOM|MUErrorHandler |
1166 |
@@enDesc: |
1167 |
When a <IF::ecore|ErrorInterface||ManakaiDOM|Perl> is <Perl::report>ed, |
1168 |
then this method is invoked. |
1169 |
|
1170 |
The method calls the <cfg::DOMCore|error-handler> if the error is of |
1171 |
<IF::DOMCore|DOMError>. Otherwise, the error is re-thrown so that |
1172 |
corresponding <Perl::catch> clause, if any, can catch the error. |
1173 |
@@Param: |
1174 |
@@@Name: err |
1175 |
@@@Type: ecore|ErrorInterface||ManakaiDOM|Perl |
1176 |
@@@enDesc: |
1177 |
The reported error object. |
1178 |
@@Return: |
1179 |
@@@Type: DISPerl|Any |
1180 |
@@@enDesc: |
1181 |
If the <P::err> is a <IF::DOMCore|DOMError>, then the return value |
1182 |
of the error handler. |
1183 |
|
1184 |
{NOTE:: If the error is thrown, the method never returns. |
1185 |
} |
1186 |
@@@nullCase: |
1187 |
@@@@enDesc: |
1188 |
No error handler. |
1189 |
@@@PerlDef: |
1190 |
if ($err->isa (<IFName::DOMCore|DOMError||ManakaiDOM|ManakaiDOM>)) { |
1191 |
__DEEP{ |
1192 |
A: { |
1193 |
my $cfg = $self-><AG::H2HParser.domConfig>; |
1194 |
my $h = $cfg-><M::DOMCore|DOMConfiguration.getParameter> |
1195 |
('error-handler'); |
1196 |
$r = $h-><M::DOMCore|DOMErrorHandler.handleError> ($err); |
1197 |
} # A |
1198 |
}__; |
1199 |
} else { |
1200 |
$err-><M::ecore|ErrorInterface||ManakaiDOM|Perl.throw>; |
1201 |
} |
1202 |
|
1203 |
@PTests: |
1204 |
@@PTest: |
1205 |
@@@QName: p.magic.sw09.test |
1206 |
@@@DEnt: |
1207 |
@@@@test:value: |
1208 |
#?SuikaWiki/0.9 |
1209 |
@@@test:domTree: |
1210 |
document { |
1211 |
element { |
1212 |
namespace-uri: 'urn:x-suika-fam-cx:markup:suikawiki:0:9:'; |
1213 |
local-name: 'document'; |
1214 |
markup-language-name: 'SuikaWiki'; |
1215 |
markup-language-version: '0.9'; |
1216 |
element { |
1217 |
namespace-uri: 'http://www.w3.org/2002/06/xhtml2/'; |
1218 |
local-name: 'head'; |
1219 |
has-child-nodes: false; |
1220 |
} |
1221 |
element { |
1222 |
namespace-uri: 'http://www.w3.org/2002/06/xhtml2/'; |
1223 |
local-name: 'body'; |
1224 |
has-child-nodes: false; |
1225 |
} |
1226 |
} |
1227 |
} |
1228 |
@@PTest: |
1229 |
@@@QName: p.magic.swimg09.test |
1230 |
@@@DEnt: |
1231 |
@@@@test:value: |
1232 |
#?SuikaWikiImage/0.9 |
1233 |
@@@test:domTree: |
1234 |
document { |
1235 |
element { |
1236 |
namespace-uri: 'urn:x-suika-fam-cx:markup:suikawiki:0:9:'; |
1237 |
local-name: 'document'; |
1238 |
markup-language-name: 'SuikaWikiImage'; |
1239 |
markup-language-version: '0.9'; |
1240 |
element { |
1241 |
namespace-uri: 'http://www.w3.org/2002/06/xhtml2/'; |
1242 |
local-name: 'head'; |
1243 |
has-child-nodes: false; |
1244 |
} |
1245 |
element { |
1246 |
namespace-uri: 'http://www.w3.org/2002/06/xhtml2/'; |
1247 |
local-name: 'body'; |
1248 |
has-child-nodes: false; |
1249 |
} |
1250 |
} |
1251 |
} |
1252 |
|
1253 |
@@PerlDef: |
1254 |
my $impl = $Message::DOM::ImplementationRegistry->get_implementation ({ |
1255 |
'Core' => '3.0', |
1256 |
'XML' => '3.0', |
1257 |
}); |
1258 |
|
1259 |
for my $test_data (@$TestData) { |
1260 |
my $parser = <Class::ManakaiH2HParser>->new ($impl); |
1261 |
|
1262 |
$test->start_new_test ($test_data->{uri}); |
1263 |
my $doc_ent = $test_data->{entity}->{$test_data->{root_uri}}; |
1264 |
my $not_ok; |
1265 |
|
1266 |
## -- DOM Configuration Parameters |
1267 |
|
1268 |
my $pcfg = $parser->dom_config; |
1269 |
for (keys %{$test_data->{dom_config}}) { |
1270 |
$pcfg->set_parameter ($_ => $test_data->{dom_config}->{$_}); |
1271 |
} |
1272 |
|
1273 |
# $pcfg->set_parameter ('error-handler' => sub ($$) { |
1274 |
# my (undef, $err) = @_; |
1275 |
# my $err_type = $err->type; |
1276 |
# if ($test_data->{dom_error}->{$err_type}) { |
1277 |
# $test->assert_error_equals |
1278 |
# (actual_value => $err, |
1279 |
# expected_hash => shift @{$test_data->{dom_error} |
1280 |
# ->{$err_type}}); |
1281 |
# } else { # Uncatched error |
1282 |
# warn $err; |
1283 |
# unless ($err->severity == <C::c|DOMError.SEVERITY_WARNING>) { |
1284 |
# $test->failure_comment ('Unexpected error |'.$err->type.'|'); |
1285 |
# $not_ok = true; |
1286 |
# } |
1287 |
# } |
1288 |
# return true; # continue as far as possible |
1289 |
# }); |
1290 |
|
1291 |
## -- Test and Result |
1292 |
|
1293 |
my $doc; |
1294 |
try { |
1295 |
$doc = $parser->parse_string ($doc_ent->{<Q::test|value>}); |
1296 |
$test->assert_dom_tree_equals |
1297 |
(actual_value => $doc, |
1298 |
expected_hash => $test_data->{dom_tree}); |
1299 |
for (values %{$test_data->{dom_error}||{}}) { |
1300 |
if (@$_) { |
1301 |
$test->failure_comment |
1302 |
(@$_.' |DOMError|s of type |'. |
1303 |
$_->[0]->{type}->{value}.'| are not reported'); |
1304 |
$not_ok = true; |
1305 |
} |
1306 |
} |
1307 |
$not_ok ? $test->not_ok : $test->ok; |
1308 |
undef $doc; |
1309 |
} catch Message::Util::IF::DTException with { |
1310 |
require Message::DOM::SimpleLS; |
1311 |
my $ls = Message::DOM::SimpleLS::ManakaiDOMSimpleXMLSerializer->new; |
1312 |
print STDERR $ls->write_to_string ($doc); |
1313 |
} otherwise { |
1314 |
my $err = shift; |
1315 |
warn $err; |
1316 |
$test->not_ok; |
1317 |
}; |
1318 |
} |
1319 |
##H2HParser |
1320 |
|