Class: HTML5::InBodyPhase
- Inherits:
-
Phase
- Object
- Phase
- HTML5::InBodyPhase
show all
- Defined in:
- lib/html5/html5parser/in_body_phase.rb
Instance Method Summary
collapse
-
#endTagBlock(name) ⇒ Object
-
#endTagBody(name) ⇒ Object
-
#endTagBr(name) ⇒ Object
-
#endTagButtonMarqueeObject(name) ⇒ Object
-
#endTagCdataTextAreaXmp(name) ⇒ Object
-
#endTagForm(name) ⇒ Object
-
#endTagFormatting(name) ⇒ Object
The much-feared adoption agency algorithm.
-
#endTagHeading(name) ⇒ Object
-
#endTagHtml(name) ⇒ Object
-
#endTagListItem(name) ⇒ Object
-
#endTagMisplaced(name) ⇒ Object
-
#endTagNew(name) ⇒ Object
-
#endTagNone(name) ⇒ Object
-
#endTagOther(name) ⇒ Object
-
#endTagP(name) ⇒ Object
-
#initialize(parser, tree) ⇒ InBodyPhase
constructor
A new instance of InBodyPhase.
-
#processCharacters(data) ⇒ Object
-
#processSpaceCharacters(data) ⇒ Object
-
#processSpaceCharactersDropNewline(data) ⇒ Object
-
#startTagA(name, attributes) ⇒ Object
-
#startTagBody(name, attributes) ⇒ Object
-
#startTagButton(name, attributes) ⇒ Object
-
#startTagCdata(name, attributes) ⇒ Object
iframe, noembed noframes, noscript(if scripting enabled).
-
#startTagCloseP(name, attributes) ⇒ Object
-
#startTagForm(name, attributes) ⇒ Object
-
#startTagFormatting(name, attributes) ⇒ Object
-
#startTagHeading(name, attributes) ⇒ Object
-
#startTagHr(name, attributes) ⇒ Object
-
#startTagImage(name, attributes) ⇒ Object
-
#startTagInput(name, attributes) ⇒ Object
-
#startTagIsindex(name, attributes) ⇒ Object
-
#startTagListItem(name, attributes) ⇒ Object
-
#startTagMarqueeObject(name, attributes) ⇒ Object
-
#startTagMisplaced(name, attributes) ⇒ Object
-
#startTagNew(name, attributes) ⇒ Object
-
#startTagNobr(name, attributes) ⇒ Object
-
#startTagOther(name, attributes) ⇒ Object
-
#startTagPlaintext(name, attributes) ⇒ Object
-
#startTagProcessInHead(name, attributes) ⇒ Object
-
#startTagSelect(name, attributes) ⇒ Object
-
#startTagTable(name, attributes) ⇒ Object
-
#startTagTextarea(name, attributes) ⇒ Object
-
#startTagTitle(name, attributes) ⇒ Object
-
#startTagVoidFormatting(name, attributes) ⇒ Object
-
#startTagXmp(name, attributes) ⇒ Object
Methods inherited from Phase
#assert, end_tag_handlers, handle_end, handle_start, #in_scope?, #processComment, #processDoctype, #processEndTag, #processStartTag, #process_eof, #remove_open_elements_until, #startTagHtml, start_tag_handlers, tag_handlers
Constructor Details
#initialize(parser, tree) ⇒ InBodyPhase
Returns a new instance of InBodyPhase.
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 49
def initialize(parser, tree)
super(parser, tree)
@processSpaceCharactersDropNewline = false
if $-w
$-w = false
alias processSpaceCharactersNonPre processSpaceCharacters
$-w = true
else
alias processSpaceCharactersNonPre processSpaceCharacters
end
end
|
Instance Method Details
#endTagBlock(name) ⇒ Object
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 365
def endTagBlock(name)
@processSpaceCharactersDropNewline = false if name == 'pre'
@tree.generateImpliedEndTags if in_scope?(name)
unless @tree.open_elements.last.name == name
parse_error("end-tag-too-early", {"name" => name})
end
if in_scope?(name)
remove_open_elements_until(name)
end
end
|
#endTagBody(name) ⇒ Object
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 343
def endTagBody(name)
unless @tree.open_elements[1].name == 'body'
parse_error
return
end
unless @tree.open_elements.last.name == 'body'
parse_error("expected-one-end-tag-but-got-another",
{"expectedName" => "body",
"gotName" => @tree.open_elements.last.name})
end
@parser.phase = @parser.phases[:afterBody]
end
|
#endTagBr(name) ⇒ Object
554
555
556
557
558
559
560
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 554
def endTagBr(name)
parse_error("unexpected-end-tag-treated-as",
{"originalName" => "br", "newName" => "br element"})
@tree.reconstructActiveFormattingElements
@tree.insert_element(name, {})
@tree.open_elements.pop()
end
|
535
536
537
538
539
540
541
542
543
544
545
546
547
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 535
def endTagButtonMarqueeObject(name)
@tree.generateImpliedEndTags if in_scope?(name)
unless @tree.open_elements.last.name == name
parse_error("end-tag-too-early", {"name" => name})
end
if in_scope?(name)
remove_open_elements_until(name)
@tree.clearActiveFormattingElements
end
end
|
#endTagCdataTextAreaXmp(name) ⇒ Object
567
568
569
570
571
572
573
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 567
def endTagCdataTextAreaXmp(name)
if @tree.open_elements.last.name == name
@tree.open_elements.pop
else
parse_error("unexpected-end-tag", {"name" => name})
end
end
|
380
381
382
383
384
385
386
387
388
389
390
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 380
def endTagForm(name)
if in_scope?(name)
@tree.generateImpliedEndTags
end
if @tree.open_elements.last.name != name
parse_error("end-tag-too-early-ignored", {"name" => "form"})
else
@tree.open_elements.pop
end
@tree.formPointer = nil
end
|
The much-feared adoption agency algorithm
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 424
def endTagFormatting(name)
while true
afeElement = @tree.elementInActiveFormattingElements(name)
if !afeElement or (@tree.open_elements.include?(afeElement) && !in_scope?(afeElement.name))
parse_error("adoption-agency-1.1", {"name" => name})
return
elsif not @tree.open_elements.include?(afeElement)
parse_error("adoption-agency-1.2", {"name" => name})
@tree.activeFormattingElements.delete(afeElement)
return
end
if afeElement != @tree.open_elements.last
parse_error("adoption-agency-1.3", {"name" => name})
end
afeIndex = @tree.open_elements.index(afeElement)
furthestBlock = nil
@tree.open_elements[afeIndex..-1].each do |element|
if (SPECIAL_ELEMENTS + SCOPING_ELEMENTS).include?(element.name)
furthestBlock = element
break
end
end
if furthestBlock.nil?
element = remove_open_elements_until {|element| element == afeElement }
@tree.activeFormattingElements.delete(element)
return
end
commonAncestor = @tree.open_elements[afeIndex - 1]
furthestBlock.parent.removeChild(furthestBlock) if furthestBlock.parent
bookmark = @tree.activeFormattingElements.index(afeElement)
lastNode = node = furthestBlock
while true
node = @tree.open_elements[@tree.open_elements.index(node) - 1]
until @tree.activeFormattingElements.include?(node)
tmpNode = node
node = @tree.open_elements[@tree.open_elements.index(node) - 1]
@tree.open_elements.delete(tmpNode)
end
break if node == afeElement
if lastNode == furthestBlock
bookmark = @tree.activeFormattingElements.index(node) + 1
end
cite = node.parent
if node.hasContent
clone = node.cloneNode
@tree.activeFormattingElements[@tree.activeFormattingElements.index(node)] = clone
@tree.open_elements[@tree.open_elements.index(node)] = clone
node = clone
end
lastNode.parent.removeChild(lastNode) if lastNode.parent
node.appendChild(lastNode)
lastNode = node
end
lastNode.parent.removeChild(lastNode) if lastNode.parent
commonAncestor.appendChild(lastNode)
clone = afeElement.cloneNode
furthestBlock.reparentChildren(clone)
furthestBlock.appendChild(clone)
@tree.activeFormattingElements.delete(afeElement)
@tree.activeFormattingElements.insert([bookmark,@tree.activeFormattingElements.length].min, clone)
@tree.open_elements.delete(afeElement)
@tree.open_elements.insert(@tree.open_elements.index(furthestBlock) + 1, clone)
end
end
|
#endTagHeading(name) ⇒ Object
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 403
def endTagHeading(name)
HEADING_ELEMENTS.each do |element|
if in_scope?(element)
@tree.generateImpliedEndTags
break
end
end
unless @tree.open_elements.last.name == name
parse_error("end-tag-too-early", {"name" => name})
end
HEADING_ELEMENTS.each do |element|
if in_scope?(element)
remove_open_elements_until {|element| HEADING_ELEMENTS.include?(element.name)}
break
end
end
end
|
#endTagHtml(name) ⇒ Object
360
361
362
363
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 360
def endTagHtml(name)
endTagBody(name)
@parser.phase.processEndTag(name) unless @parser.inner_html
end
|
#endTagListItem(name) ⇒ Object
392
393
394
395
396
397
398
399
400
401
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 392
def endTagListItem(name)
@tree.generateImpliedEndTags(name) if in_scope?(name)
unless @tree.open_elements.last.name == name
parse_error("end-tag-too-early", {"name" => name})
end
remove_open_elements_until(name) if in_scope?(name)
end
|
#endTagMisplaced(name) ⇒ Object
549
550
551
552
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 549
def endTagMisplaced(name)
parse_error("unexpected-end-tag", {"name" => name})
end
|
#endTagNew(name) ⇒ Object
575
576
577
578
579
580
581
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 575
def endTagNew(name)
endTagOther(name)
end
|
#endTagNone(name) ⇒ Object
562
563
564
565
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 562
def endTagNone(name)
parse_error("no-end-tag", {"name" => name})
end
|
#endTagOther(name) ⇒ Object
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 583
def endTagOther(name)
@tree.open_elements.reverse.each do |node|
if node.name == name
@tree.generateImpliedEndTags
unless @tree.open_elements.last.name == name
parse_error("unexpected-end-tag", {"name" => name})
end
remove_open_elements_until {|element| element == node }
break
else
if (SPECIAL_ELEMENTS + SCOPING_ELEMENTS).include?(node.name)
parse_error("unexpected-end-tag", {"name" => name})
break
end
end
end
end
|
#endTagP(name) ⇒ Object
332
333
334
335
336
337
338
339
340
341
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 332
def endTagP(name)
@tree.generateImpliedEndTags('p') if in_scope?('p')
parse_error("unexpected-end-tag", {"name" => "p"}) unless @tree.open_elements.last.name == 'p'
if in_scope?('p')
@tree.open_elements.pop while in_scope?('p')
else
startTagCloseP('p', {})
endTagP('p')
end
end
|
#processCharacters(data) ⇒ Object
90
91
92
93
94
95
96
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 90
def processCharacters(data)
@tree.reconstructActiveFormattingElements
@tree.insertText(data)
end
|
#processSpaceCharacters(data) ⇒ Object
85
86
87
88
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 85
def processSpaceCharacters(data)
@tree.reconstructActiveFormattingElements()
@tree.insertText(data)
end
|
#processSpaceCharactersDropNewline(data) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 63
def processSpaceCharactersDropNewline(data)
if $-w
$-w = false
alias processSpaceCharacters processSpaceCharactersNonPre
$-w = true
else
alias processSpaceCharacters processSpaceCharactersNonPre
end
if (data.length > 0 and data[0] == ?\n &&
%w[pre textarea].include?(@tree.open_elements.last.name) && !@tree.open_elements.last.hasContent)
data = data[1..-1]
end
if data.length > 0
@tree.reconstructActiveFormattingElements
@tree.insertText(data)
end
end
|
#startTagA(name, attributes) ⇒ Object
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 187
def startTagA(name, attributes)
if afeAElement = @tree.elementInActiveFormattingElements('a')
parse_error("unexpected-start-tag-implies-end-tag", {"startName" => "a", "endName" => "a"})
endTagFormatting('a')
@tree.open_elements.delete(afeAElement) if @tree.open_elements.include?(afeAElement)
@tree.activeFormattingElements.delete(afeAElement) if @tree.activeFormattingElements.include?(afeAElement)
end
@tree.reconstructActiveFormattingElements
addFormattingElement(name, attributes)
end
|
#startTagBody(name, attributes) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 107
def startTagBody(name, attributes)
parse_error("unexpected-start-tag", {"name" => "body"})
if @tree.open_elements.length == 1 || @tree.open_elements[1].name != 'body'
assert @parser.inner_html
else
attributes.each do |attr, value|
unless @tree.open_elements[1].attributes.has_key?(attr)
@tree.open_elements[1].attributes[attr] = value
end
end
end
end
|
214
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 214
def startTagButton(name, attributes)
if in_scope?('button')
parse_error("unexpected-start-tag-implies-end-tag", {"startName" => "button", "endName" => "button"})
processEndTag('button')
@parser.phase.processStartTag(name, attributes)
else
@tree.reconstructActiveFormattingElements
@tree.insert_element(name, attributes)
@tree.activeFormattingElements.push(Marker)
end
end
|
#startTagCdata(name, attributes) ⇒ Object
iframe, noembed noframes, noscript(if scripting enabled)
299
300
301
302
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 299
def startTagCdata(name, attributes)
@tree.insert_element(name, attributes)
@parser.tokenizer.content_model_flag = :CDATA
end
|
#startTagCloseP(name, attributes) ⇒ Object
121
122
123
124
125
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 121
def startTagCloseP(name, attributes)
endTagP('p') if in_scope?('p')
@tree.insert_element(name, attributes)
@processSpaceCharactersDropNewline = true if name == 'pre'
end
|
127
128
129
130
131
132
133
134
135
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 127
def startTagForm(name, attributes)
if @tree.formPointer
parse_error("unexpected-start-tag", {"name" => name})
else
endTagP('p') if in_scope?('p')
@tree.insert_element(name, attributes)
@tree.formPointer = @tree.open_elements.last
end
end
|
198
199
200
201
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 198
def startTagFormatting(name, attributes)
@tree.reconstructActiveFormattingElements
addFormattingElement(name, attributes)
end
|
#startTagHeading(name, attributes) ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 169
def startTagHeading(name, attributes)
endTagP('p') if in_scope?('p')
@tree.insert_element(name, attributes)
end
|
#startTagHr(name, attributes) ⇒ Object
250
251
252
253
254
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 250
def startTagHr(name, attributes)
endTagP('p') if in_scope?('p')
@tree.insert_element(name, attributes)
@tree.open_elements.pop
end
|
#startTagImage(name, attributes) ⇒ Object
256
257
258
259
260
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 256
def startTagImage(name, attributes)
parse_error("unexpected-start-tag-treated-as", {"originalName" => "image", "newName" => "img"})
processStartTag('img', attributes)
end
|
262
263
264
265
266
267
268
269
270
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 262
def startTagInput(name, attributes)
@tree.reconstructActiveFormattingElements
@tree.insert_element(name, attributes)
if @tree.formPointer
end
@tree.open_elements.pop
end
|
#startTagIsindex(name, attributes) ⇒ Object
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 272
def startTagIsindex(name, attributes)
parse_error("deprecated-tag", {"name" => "isindex"})
return if @tree.formPointer
processStartTag('form', {})
processStartTag('hr', {})
processStartTag('p', {})
processStartTag('label', {})
processCharacters('This is a searchable index. Insert your search keywords here: ')
attributes['name'] = 'isindex'
attrs = attributes.to_a
processStartTag('input', attributes)
processEndTag('label')
processEndTag('p')
processStartTag('hr', {})
processEndTag('form')
end
|
#startTagListItem(name, attributes) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 137
def startTagListItem(name, attributes)
endTagP('p') if in_scope?('p')
stopNames = {'li' => ['li'], 'dd' => ['dd', 'dt'], 'dt' => ['dd', 'dt']}
stopName = stopNames[name]
@tree.open_elements.reverse.each_with_index do |node, i|
if stopName.include?(node.name)
poppedNodes = (0..i).collect { @tree.open_elements.pop }
if i >= 1
parse_error(
i == 1 ? "missing-end-tag" : "missing-end-tags",
{"name" => poppedNodes[0..-1].collect{|n| n.name}.join(", ")})
end
break
end
break if ((SPECIAL_ELEMENTS + SCOPING_ELEMENTS).include?(node.name) && !%w[address div].include?(node.name))
end
@tree.insert_element(name, attributes)
end
|
#startTagMarqueeObject(name, attributes) ⇒ Object
226
227
228
229
230
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 226
def startTagMarqueeObject(name, attributes)
@tree.reconstructActiveFormattingElements
@tree.insert_element(name, attributes)
@tree.activeFormattingElements.push(Marker)
end
|
#startTagMisplaced(name, attributes) ⇒ Object
310
311
312
313
314
315
316
317
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 310
def startTagMisplaced(name, attributes)
parse_error("unexpected-start-tag-ignored", {"name" => name})
end
|
#startTagNew(name, attributes) ⇒ Object
319
320
321
322
323
324
325
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 319
def startTagNew(name, attributes)
startTagOther(name, attributes)
end
|
#startTagNobr(name, attributes) ⇒ Object
203
204
205
206
207
208
209
210
211
212
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 203
def startTagNobr(name, attributes)
@tree.reconstructActiveFormattingElements
if in_scope?('nobr')
parse_error("unexpected-start-tag-implies-end-tag", {"startName" => "nobr", "endName" => "nobr"})
processEndTag('nobr')
@tree.reconstructActiveFormattingElements
end
addFormattingElement(name, attributes)
end
|
#startTagOther(name, attributes) ⇒ Object
327
328
329
330
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 327
def startTagOther(name, attributes)
@tree.reconstructActiveFormattingElements
@tree.insert_element(name, attributes)
end
|
#startTagPlaintext(name, attributes) ⇒ Object
163
164
165
166
167
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 163
def startTagPlaintext(name, attributes)
endTagP('p') if in_scope?('p')
@tree.insert_element(name, attributes)
@parser.tokenizer.content_model_flag = :PLAINTEXT
end
|
#startTagProcessInHead(name, attributes) ⇒ Object
98
99
100
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 98
def startTagProcessInHead(name, attributes)
@parser.phases[:inHead].processStartTag(name, attributes)
end
|
304
305
306
307
308
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 304
def startTagSelect(name, attributes)
@tree.reconstructActiveFormattingElements
@tree.insert_element(name, attributes)
@parser.phase = @parser.phases[:inSelect]
end
|
#startTagTable(name, attributes) ⇒ Object
238
239
240
241
242
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 238
def startTagTable(name, attributes)
processEndTag('p') if in_scope?('p')
@tree.insert_element(name, attributes)
@parser.phase = @parser.phases[:inTable]
end
|
#startTagTextarea(name, attributes) ⇒ Object
290
291
292
293
294
295
296
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 290
def startTagTextarea(name, attributes)
@tree.insert_element(name, attributes)
@parser.tokenizer.content_model_flag = :RCDATA
@processSpaceCharactersDropNewline = true
alias processSpaceCharacters processSpaceCharactersDropNewline
end
|
#startTagTitle(name, attributes) ⇒ Object
102
103
104
105
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 102
def startTagTitle(name, attributes)
parse_error("unexpected-start-tag-out-of-my-head", {"name" => name})
@parser.phases[:inHead].processStartTag(name, attributes)
end
|
244
245
246
247
248
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 244
def startTagVoidFormatting(name, attributes)
@tree.reconstructActiveFormattingElements
@tree.insert_element(name, attributes)
@tree.open_elements.pop
end
|
#startTagXmp(name, attributes) ⇒ Object
232
233
234
235
236
|
# File 'lib/html5/html5parser/in_body_phase.rb', line 232
def startTagXmp(name, attributes)
@tree.reconstructActiveFormattingElements
@tree.insert_element(name, attributes)
@parser.tokenizer.content_model_flag = :CDATA
end
|