fasthtmlparser 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,706 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FastHtmlParser
4
+ # One tag of a document. Positions are byte offsets into the document source (String#byteslice works with them).
5
+ # Methods that look for another tag return nil when there is none; methods that read a value return "" when there
6
+ # is none. Strings are UTF-8.
7
+ class HtmlNode
8
+ TAG_SYMBOLS = TagNames::NAMES.map(&:to_sym).freeze
9
+ TEXT_SPECIAL = /[<&\r]/n
10
+
11
+ # The document the tag belongs to.
12
+ attr_reader :doc
13
+ # The position of the tag in the document.
14
+ attr_reader :index
15
+ # The byte offset of the opening '<' in the source.
16
+ attr_reader :start
17
+ # The byte offset of the last '>': of the end tag when there is one, otherwise of the opening tag.
18
+ attr_reader :end
19
+ # The nesting depth: 0 for top-level tags.
20
+ attr_reader :depth
21
+ # The index of the enclosing tag, -1 at the top level.
22
+ attr_reader :parent_index
23
+ # The byte offset right after the opening tag; 0 when the tag is not closed.
24
+ attr_reader :inner_start
25
+ # The byte offset of the last byte before the end tag; 0 when the tag is not closed.
26
+ attr_reader :inner_end
27
+ # @api private Tag key, or -1 for a name that is not in Tag
28
+ attr_reader :key
29
+ # @api private the lower-case name (binary) of a tag that is not in Tag, "" for the others
30
+ attr_reader :custom
31
+
32
+ alias document doc
33
+
34
+ # @api private Tags are made by the document: HtmlDocument#node.
35
+ def initialize(doc, i)
36
+ @doc = doc
37
+ @index = i
38
+ @parent_index = doc.parents[i]
39
+ @key = doc.keys[i]
40
+ @custom = doc.customs[i]
41
+ @start = doc.starts[i]
42
+ @end = doc.ends[i]
43
+ @inner_start = doc.inner_starts[i]
44
+ @inner_end = doc.inner_ends[i]
45
+ @depth = doc.depths[i]
46
+ @lower_tag = nil
47
+ end
48
+
49
+ # @api private The opening tag ("<name attributes", without the closing '>') in lower case, read once.
50
+ def lower_tag
51
+ @lower_tag ||= begin
52
+ end_ = @inner_start > 0 && @inner_end > 0 ? @inner_start - 1 : @end
53
+ t = @doc.source_bytes.byteslice(@start, end_ - @start)
54
+ t.downcase!
55
+ t.freeze
56
+ end
57
+ end
58
+
59
+ def ==(other)
60
+ other.is_a?(HtmlNode) && other.doc.equal?(@doc) && other.index == @index
61
+ end
62
+ alias eql? ==
63
+
64
+ def hash
65
+ [@doc.object_id, @index].hash
66
+ end
67
+
68
+ # ----- reading a tag -----
69
+
70
+ # The tag as a Symbol (:div, :"!--" for comments), or nil for a name that is not one of the known tags.
71
+ def tag
72
+ @key >= 0 ? TAG_SYMBOLS[@key] : nil
73
+ end
74
+
75
+ # The lower-case tag name ("div", "!--" for comments, "custom-tag", ...).
76
+ def name
77
+ @key >= 0 ? TagNames::NAMES[@key] : Chars.u(@custom)
78
+ end
79
+
80
+ # @api private name as binary bytes
81
+ def name_bytes
82
+ @key >= 0 ? TagNames::NAMES[@key] : @custom
83
+ end
84
+
85
+ # The inner HTML (trimmed); "" for tags that are not closed.
86
+ def body
87
+ Chars.u(body_bytes)
88
+ end
89
+
90
+ # @api private
91
+ def body_bytes
92
+ is = @inner_start
93
+ ie = @inner_end
94
+ return +"".b if is < 0 || ie <= 0
95
+
96
+ src = @doc.source_bytes
97
+ first = src.getbyte(is)
98
+ last = src.getbyte(ie)
99
+ # nearly always nothing to trim
100
+ return src.byteslice(is, ie + 1 - is) if first && first > 32 && first < 0xc2 && last > 32 && last < 0x80
101
+
102
+ Chars.trim_range(src, is, ie + 1)
103
+ end
104
+
105
+ # The source of the whole element; "" for tags that are not closed.
106
+ def outer_html
107
+ return +"" if @inner_start <= 0 || @inner_end <= 0
108
+
109
+ Chars.u(Chars.trim_range(@doc.source_bytes, @start, @end + 1))
110
+ end
111
+
112
+ # The visible text with entities decoded. With child tags: tags, comments and the content of script, style,
113
+ # noscript, template, noframes, noembed removed, whitespace collapsed; without: the inner text as is (trimmed).
114
+ def text
115
+ Chars.u(text_bytes)
116
+ end
117
+
118
+ # @api private
119
+ def text_bytes
120
+ body = body_bytes
121
+ # no tags, references or CR: the body is the text
122
+ return body unless TEXT_SPECIAL.match?(body)
123
+
124
+ # No child tags and no '<' at all: the body is the text, except in script, style, textarea, title, ...
125
+ if !has_children? && (!body.include?(Text::LT) || Parser.raw_text?(@key))
126
+ return Decode.needs_decoding?(body) ? Decode.decode(body, false) : body
127
+ end
128
+
129
+ Text.clear_tags(body)
130
+ end
131
+
132
+ # The text with the visible line structure kept: <br> and block elements give new lines, p and headings a blank
133
+ # line, td / th a space; lines are trimmed and joined with "\n".
134
+ def text_line_breaks
135
+ return +"" if @inner_start < 0 || @inner_end <= 0
136
+
137
+ Chars.u(TextLines.clear_tags_line_breaks(body_bytes))
138
+ end
139
+
140
+ # Whether another tag starts inside this one.
141
+ def has_children?
142
+ i = @index + 1
143
+ i < @doc.size && @doc.starts[i] < @end
144
+ end
145
+
146
+ # The opening tag without '<' and '>': the name and the attributes.
147
+ def source
148
+ Chars.u(source_bytes)
149
+ end
150
+
151
+ # @api private
152
+ def source_bytes
153
+ src = @doc.source_bytes
154
+ length = if @inner_start > 0 && @inner_end > 0
155
+ @inner_start - @start - 2
156
+ elsif @end > 0 && @end - 1 < src.bytesize && src.getbyte(@end - 1) == 47
157
+ @end - @start - 2
158
+ else
159
+ @end - @start - 1
160
+ end
161
+ Chars.trim_range(src, @start + 1, @start + 1 + length)
162
+ end
163
+
164
+ def to_s
165
+ "<#{source}>"
166
+ end
167
+
168
+ def inspect
169
+ "#<#{self.class.name} #{index} #{to_s[0, 80]}>"
170
+ end
171
+
172
+ # ----- attributes -----
173
+
174
+ # The decoded value of the first attribute with the name (case-insensitive); "" when it is missing or has no
175
+ # value.
176
+ def attr(name)
177
+ Chars.u(Attrs.attr_value(self, attr_name(name)))
178
+ end
179
+
180
+ # The value of the attribute as written in the source.
181
+ def attr_raw(name)
182
+ Chars.u(Attrs.attr_raw(self, attr_name(name)))
183
+ end
184
+
185
+ # Whether the tag has the attribute, with or without a value (case-insensitive name).
186
+ def has_attr?(name)
187
+ Attrs.has_attribute?(self, attr_name(name))
188
+ end
189
+
190
+ # Whether one of the space-separated classes equals cls (case-insensitive).
191
+ def has_class?(cls)
192
+ Attrs.has_class?(self, Chars.b(cls))
193
+ end
194
+
195
+ # Every attribute of the opening tag: [name as written, raw value] pairs in source order.
196
+ def attrs
197
+ out = []
198
+ return out if @key == Parser::COMMENT
199
+
200
+ s = AttrScanner.new(self)
201
+ out << [Chars.u(s.name), Chars.u(s.raw_value)] while s.next?
202
+ out
203
+ end
204
+
205
+ # The link a browser follows: href decoded and made absolute against the page URL; an empty or missing href gives
206
+ # the page URL.
207
+ def href
208
+ Chars.u(Links.correct_link(Attrs.attr_raw(self, "href"), @doc.url_bytes, @doc.base))
209
+ end
210
+
211
+ # href resolved against base_url instead of the page URL.
212
+ def href_from(base_url)
213
+ base = Chars.b(base_url)
214
+ Chars.u(Links.correct_link(Attrs.attr_raw(self, "href"), base, Links.absolute_url(base)))
215
+ end
216
+
217
+ # The src attribute decoded and made absolute against the page URL.
218
+ def src
219
+ Chars.u(Links.correct_link(Attrs.attr_raw(self, "src"), @doc.url_bytes, @doc.base))
220
+ end
221
+
222
+ # src resolved against base_url instead of the page URL.
223
+ def src_from(base_url)
224
+ base = Chars.b(base_url)
225
+ Chars.u(Links.correct_link(Attrs.attr_raw(self, "src"), base, Links.absolute_url(base)))
226
+ end
227
+
228
+ # The address of a mailto: link (everything after the first ':'), or "".
229
+ def href_mail_to
230
+ Chars.u(Links.after_scheme(Attrs.attr_raw(self, "href"), "mailto"))
231
+ end
232
+
233
+ # The number of a tel: link (everything after the first ':'), or "".
234
+ def href_telephone
235
+ Chars.u(Links.after_scheme(Attrs.attr_raw(self, "href"), "tel"))
236
+ end
237
+
238
+ # ----- navigation -----
239
+
240
+ # The enclosing tag, or nil.
241
+ def parent
242
+ @parent_index >= 0 ? @doc.at(@parent_index) : nil
243
+ end
244
+
245
+ # The direct children: the tags inside this one, one level deeper.
246
+ def children
247
+ out = []
248
+ d = @doc
249
+ ends = d.ends
250
+ depths = d.depths
251
+ depth = @depth + 1
252
+ i = @index + 1
253
+ count = d.size
254
+ while i < count && ends[i] <= @end
255
+ out << d.at(i) if depths[i] == depth
256
+ i += 1
257
+ end
258
+ out
259
+ end
260
+
261
+ # The tag that follows in document order (the first child, if there is one), or nil.
262
+ def next
263
+ @doc.node(@index + 1)
264
+ end
265
+
266
+ # The tag before this one in document order, or nil.
267
+ def previous
268
+ @index > 0 ? @doc.at(@index - 1) : nil
269
+ end
270
+
271
+ # The first tag after the end of this one that matches the query (tags inside it are skipped), or nil.
272
+ def next_matching(query)
273
+ d = @doc
274
+ starts = d.starts
275
+ i = @index + 1
276
+ count = d.size
277
+ while i < count
278
+ return d.at(i) if starts[i] > @end && query.name_matches_at?(d, i) && query.matches?(d.at(i))
279
+
280
+ i += 1
281
+ end
282
+ nil
283
+ end
284
+
285
+ # The next tag at the same level inside the same parent, or nil.
286
+ def next_sibling
287
+ next_sibling_matching(Query.any)
288
+ end
289
+
290
+ # The next sibling that matches the query, or nil.
291
+ def next_sibling_matching(query)
292
+ # deeper tags are inside the following siblings; a shallower one ends the parent
293
+ d = @doc
294
+ depths = d.depths
295
+ i = @index + 1
296
+ count = d.size
297
+ while i < count && depths[i] >= @depth
298
+ return d.at(i) if depths[i] == @depth && query.name_matches_at?(d, i) && query.matches?(d.at(i))
299
+
300
+ i += 1
301
+ end
302
+ nil
303
+ end
304
+
305
+ # The previous tag at the same level inside the same parent, or nil.
306
+ def previous_sibling
307
+ previous_sibling_matching(Query.any)
308
+ end
309
+
310
+ # The nearest previous sibling that matches the query, or nil.
311
+ def previous_sibling_matching(query)
312
+ # deeper tags are inside the previous siblings; a shallower one is the parent
313
+ d = @doc
314
+ depths = d.depths
315
+ i = @index - 1
316
+ while i >= 0 && depths[i] >= @depth
317
+ return d.at(i) if depths[i] == @depth && query.name_matches_at?(d, i) && query.matches?(d.at(i))
318
+
319
+ i -= 1
320
+ end
321
+ nil
322
+ end
323
+
324
+ # The nearest enclosing tag that matches the query, or nil.
325
+ def parent_matching(query)
326
+ p = parent
327
+ until p.nil?
328
+ return p if query.matches?(p)
329
+
330
+ p = p.parent
331
+ end
332
+ nil
333
+ end
334
+
335
+ # The source text right after the tag up to the next '<' (or the end of the page).
336
+ def text_after_tag_until_next_one
337
+ Chars.u(text_after_bytes)
338
+ end
339
+
340
+ # text_after_tag_until_next_one as visible text: entities decoded, whitespace collapsed.
341
+ def text_no_tags_after_tag_until_next_one
342
+ Chars.u(Text.clear_tags(text_after_bytes))
343
+ end
344
+
345
+ # The source between the end of the tag and the next tag that matches the query; "" when there is none.
346
+ def text_after_until(query)
347
+ until_ = next_matching(query)
348
+ until_.nil? ? +"" : Chars.u(Chars.slice(@doc.source_bytes, @end + 1, until_.start))
349
+ end
350
+
351
+ # ----- search -----
352
+
353
+ # The first tag inside this one (a descendant) that matches the query, or nil.
354
+ def find(query)
355
+ query.find_in(@doc, @index + 1, @end)
356
+ end
357
+
358
+ # All tags inside this one (descendants) that match the query.
359
+ def find_all(query)
360
+ query.find_all_in(@doc, @index + 1, @end)
361
+ end
362
+
363
+ # Whether the tag matches the query.
364
+ def is?(query)
365
+ query.matches?(self)
366
+ end
367
+
368
+ # The tags inside this one that match a CSS selector (as querySelectorAll); :scope is this tag, "> li" its
369
+ # children.
370
+ def css(selector)
371
+ CssQuery.cached(selector).all_in(self)
372
+ end
373
+
374
+ # The first tag inside this one that matches a CSS selector, or nil.
375
+ def css_first(selector)
376
+ CssQuery.cached(selector).first_in(self)
377
+ end
378
+
379
+ # Whether the tag matches a CSS selector (as element.matches()).
380
+ def is_css?(selector)
381
+ CssQuery.cached(selector).matches?(self)
382
+ end
383
+
384
+ # The tags an XPath expression selects; relative paths start at this tag, '/' and '//' search the whole document.
385
+ def xpath(expression)
386
+ XPathQuery.cached(expression).nodes_from(self)
387
+ end
388
+
389
+ # The first tag an XPath expression selects from this tag, or nil.
390
+ def xpath_first(expression)
391
+ xpath(expression).first
392
+ end
393
+
394
+ # The values an XPath expression selects from this tag.
395
+ def xpath_values(expression)
396
+ XPathQuery.cached(expression).values_from(self)
397
+ end
398
+
399
+ # The first value an XPath expression selects from this tag, or "".
400
+ def xpath_value(expression)
401
+ XPathQuery.cached(expression).value_from(self) || +""
402
+ end
403
+
404
+ private
405
+
406
+ def text_after_bytes
407
+ src = @doc.source_bytes
408
+ from = @end + 1
409
+ return +"".b if from >= src.bytesize
410
+
411
+ nxt = src.index(Text::LT, from)
412
+ nxt.nil? ? src.byteslice(from, src.bytesize - from) : src.byteslice(from, nxt - from)
413
+ end
414
+
415
+ def attr_name(name)
416
+ Chars.b(name).downcase(:ascii)
417
+ end
418
+
419
+ public
420
+
421
+ # <shortcuts node>
422
+ # Generated by tools/gen.rb; do not edit by hand.
423
+
424
+ # Returns the first tag with the id inside the tag, or nil.
425
+ def find_by_id(id)
426
+ return nil if id.empty?
427
+
428
+ find(Query.any.id(id))
429
+ end
430
+
431
+ # Returns the first tag with the name inside the tag, or nil.
432
+ def find_by_name(name)
433
+ find(Query.by(name))
434
+ end
435
+
436
+ # Returns the first tag with the name and the inner HTML inside the tag, or nil.
437
+ def find_by_name_body(name, body)
438
+ find(Query.by(name).body(body))
439
+ end
440
+
441
+ # Returns the first tag with the name and the decoded attribute value inside the tag, or nil.
442
+ def find_by_name_attribute(name, attribute, value)
443
+ find(Query.by(name).attr(attribute, value))
444
+ end
445
+
446
+ # Returns the first tag with the name and the class inside the tag, or nil.
447
+ def find_by_name_class(name, cls)
448
+ find(Query.by(name).has_class(cls))
449
+ end
450
+
451
+ # Returns the first tag with the name, the class and the inner HTML inside the tag, or nil.
452
+ def find_by_name_class_body(name, cls, body)
453
+ find(Query.by(name).has_class(cls).body(body))
454
+ end
455
+
456
+ # Returns the first tag with the name, and the class and visible text when they are not empty inside the tag, or nil.
457
+ def find_by_name_class_text(name, cls, text)
458
+ find(Query.opt_text(Query.opt_class(Query.by(name), cls), text))
459
+ end
460
+
461
+ # Returns the first tag with the name, and the id and visible text when they are not empty inside the tag, or nil.
462
+ def find_by_name_id_text(name, id, text)
463
+ find(Query.opt_text(Query.opt_id(Query.by(name), id), text))
464
+ end
465
+
466
+ # Returns the first tag with the name and the visible text inside the tag, or nil.
467
+ def find_by_name_text(name, text)
468
+ find(Query.by(name).text(text))
469
+ end
470
+
471
+ # Returns the first tag with the name and the id inside the tag, or nil.
472
+ def find_by_name_id(name, id)
473
+ find(Query.by(name).id(id))
474
+ end
475
+
476
+ # Returns the first tag with the name whose id starts with the prefix inside the tag, or nil.
477
+ def find_by_name_id_starts_with(name, id_prefix)
478
+ find(Query.by(name).id_starts_with(id_prefix))
479
+ end
480
+
481
+ # Returns the first tag with the name whose inner HTML starts with the prefix inside the tag, or nil.
482
+ def find_by_name_body_starts_with(name, body_prefix)
483
+ find(Query.by(name).body_starts_with(body_prefix))
484
+ end
485
+
486
+ # Returns the first tag with the name whose visible text starts with the prefix inside the tag, or nil.
487
+ def find_by_name_text_starts_with(name, text_prefix)
488
+ return nil if text_prefix.empty?
489
+
490
+ find(Query.by(name).text_starts_with(text_prefix))
491
+ end
492
+
493
+ # Returns the first tag with the name and the class whose visible text starts with the prefix inside the tag, or nil.
494
+ def find_by_name_class_text_starts_with(name, cls, text_prefix)
495
+ return nil if text_prefix.empty?
496
+
497
+ find(Query.by(name).has_class(cls).text_starts_with(text_prefix))
498
+ end
499
+
500
+ # Returns the first tag with the name and the itemprop inside the tag, or nil.
501
+ def find_by_name_itemprop(name, itemprop)
502
+ find(Query.by(name).attr(Attr::ITEMPROP, itemprop))
503
+ end
504
+
505
+ # Returns all tags with the name inside the tag.
506
+ def find_all_by_name(name)
507
+ find_all(Query.by(name))
508
+ end
509
+
510
+ # Returns all tags with the name and the decoded attribute value inside the tag.
511
+ def find_all_by_name_attribute(name, attribute, value)
512
+ find_all(Query.by(name).attr(attribute, value))
513
+ end
514
+
515
+ # Returns all tags with the name and the class inside the tag.
516
+ def find_all_by_name_class(name, cls)
517
+ find_all(Query.by(name).has_class(cls))
518
+ end
519
+
520
+ # Returns all tags with the name and the id inside the tag.
521
+ def find_all_by_name_id(name, id)
522
+ find_all(Query.by(name).id(id))
523
+ end
524
+
525
+ # Returns all tags with the name whose id starts with the prefix inside the tag.
526
+ def find_all_by_name_id_starts_with(name, id_prefix)
527
+ find_all(Query.by(name).id_starts_with(id_prefix))
528
+ end
529
+
530
+ # Returns all tags with the name and the itemprop inside the tag.
531
+ def find_all_by_name_itemprop(name, itemprop)
532
+ find_all(Query.by(name).attr(Attr::ITEMPROP, itemprop))
533
+ end
534
+
535
+ # Returns all tags with the name whose inner HTML starts with the prefix inside the tag.
536
+ def find_all_by_name_body_starts_with(name, body_prefix)
537
+ find_all(Query.by(name).body_starts_with(body_prefix))
538
+ end
539
+
540
+ # Whether the tag has the name and the decoded attribute value.
541
+ def is_name_attribute?(name, attribute, value)
542
+ is?(Query.by(name).attr(attribute, value))
543
+ end
544
+
545
+ # Whether the tag has the name and the inner HTML.
546
+ def is_name_body?(name, body)
547
+ is?(Query.by(name).body(body))
548
+ end
549
+
550
+ # Whether the tag has the name and the visible text.
551
+ def is_name_text?(name, text)
552
+ is?(Query.by(name).text(text))
553
+ end
554
+
555
+ # Whether the tag has the name and the class.
556
+ def is_name_class?(name, cls)
557
+ is?(Query.by(name).has_class(cls))
558
+ end
559
+
560
+ # Whether the tag has the name, the class and the inner HTML.
561
+ def is_name_class_body?(name, cls, body)
562
+ is?(Query.by(name).has_class(cls).body(body))
563
+ end
564
+
565
+ # Whether the tag has the name, and the class, id and inner HTML when they are not empty.
566
+ def is_name_class_id_body?(name, cls, id, body)
567
+ is?(Query.opt_body(Query.opt_id(Query.opt_class(Query.by(name), cls), id), body))
568
+ end
569
+
570
+ # Whether the tag has the name, and the class and visible text when they are not empty.
571
+ def is_name_class_text?(name, cls, text)
572
+ is?(Query.opt_text(Query.opt_class(Query.by(name), cls), text))
573
+ end
574
+
575
+ # Whether the tag has the name, and the id and visible text when they are not empty.
576
+ def is_name_id_text?(name, id, text)
577
+ is?(Query.opt_text(Query.opt_id(Query.by(name), id), text))
578
+ end
579
+
580
+ # Whether the tag has the name and the id.
581
+ def is_name_id?(name, id)
582
+ is?(Query.by(name).id(id))
583
+ end
584
+
585
+ # Whether the tag has the name and its visible text starts with the prefix.
586
+ def is_name_text_starts_with?(name, text_prefix)
587
+ is?(Query.by(name).text_starts_with(text_prefix))
588
+ end
589
+
590
+ # Whether the tag has the name and its inner HTML starts with the prefix.
591
+ def is_name_body_starts_with?(name, body_prefix)
592
+ is?(Query.by(name).body_starts_with(body_prefix))
593
+ end
594
+
595
+ # Whether the tag has the name and the class and its visible text starts with the prefix.
596
+ def is_name_class_text_starts_with?(name, cls, text_prefix)
597
+ is?(Query.by(name).has_class(cls).text_starts_with(text_prefix))
598
+ end
599
+
600
+ # Whether the tag has the name and its id starts with the prefix.
601
+ def is_name_id_starts_with?(name, id_prefix)
602
+ is?(Query.by(name).id_starts_with(id_prefix))
603
+ end
604
+
605
+ # Whether the tag has the name and the itemprop.
606
+ def is_name_itemprop?(name, itemprop)
607
+ is?(Query.by(name).attr(Attr::ITEMPROP, itemprop))
608
+ end
609
+
610
+ # Whether the tag has the name and its opening tag (without '<' and '>') equals source.
611
+ def is_name_source?(name, source)
612
+ is?(Query.by(name).source(source))
613
+ end
614
+
615
+ # Returns the nearest enclosing tag with the name, or nil.
616
+ def parent_by_name(name)
617
+ parent_matching(Query.by(name))
618
+ end
619
+
620
+ # Returns the nearest enclosing tag with the name and the class, or nil.
621
+ def parent_by_name_class(name, cls)
622
+ parent_matching(Query.by(name).has_class(cls))
623
+ end
624
+
625
+ # Returns the first tag with the name after the end of this one, or nil.
626
+ def next_by_name(name)
627
+ next_matching(Query.by(name))
628
+ end
629
+
630
+ # Returns the first tag with the name and the class after the end of this one, or nil.
631
+ def next_by_name_class(name, cls)
632
+ next_matching(Query.by(name).has_class(cls))
633
+ end
634
+
635
+ # Returns the next sibling with the name, or nil.
636
+ def next_sibling_by_name(name)
637
+ next_sibling_matching(Query.by(name))
638
+ end
639
+
640
+ # Returns the next sibling with the name and the class, or nil.
641
+ def next_sibling_by_name_class(name, cls)
642
+ next_sibling_matching(Query.by(name).has_class(cls))
643
+ end
644
+
645
+ # Returns the nearest previous sibling with the name, or nil.
646
+ def previous_sibling_by_name(name)
647
+ previous_sibling_matching(Query.by(name))
648
+ end
649
+
650
+ # Returns the source between the end of this tag and the next tag with the name.
651
+ def text_after_until_tag_by_name(name)
652
+ text_after_until(Query.by(name))
653
+ end
654
+
655
+ # Returns the source between the end of this tag and the next tag with the name and the class.
656
+ def text_after_until_tag_by_name_class(name, cls)
657
+ text_after_until(Query.by(name).has_class(cls))
658
+ end
659
+
660
+ # The decoded value of the alt attribute; "" when it is missing.
661
+ def attribute_alt
662
+ attr(Attr::ALT)
663
+ end
664
+
665
+ # The decoded value of the class attribute; "" when it is missing.
666
+ def attribute_class
667
+ attr(Attr::CLASS)
668
+ end
669
+
670
+ # The decoded value of the content attribute; "" when it is missing.
671
+ def attribute_content
672
+ attr(Attr::CONTENT)
673
+ end
674
+
675
+ # The decoded value of the id attribute; "" when it is missing.
676
+ def attribute_id
677
+ attr(Attr::ID)
678
+ end
679
+
680
+ # The decoded value of the itemprop attribute; "" when it is missing.
681
+ def attribute_item_prop
682
+ attr(Attr::ITEMPROP)
683
+ end
684
+
685
+ # The decoded value of the name attribute; "" when it is missing.
686
+ def attribute_name
687
+ attr(Attr::NAME)
688
+ end
689
+
690
+ # The decoded value of the style attribute; "" when it is missing.
691
+ def attribute_style
692
+ attr(Attr::STYLE)
693
+ end
694
+
695
+ # The decoded value of the title attribute; "" when it is missing.
696
+ def attribute_title
697
+ attr(Attr::TITLE)
698
+ end
699
+
700
+ # The decoded value of the value attribute; "" when it is missing.
701
+ def attribute_value
702
+ attr(Attr::VALUE)
703
+ end
704
+ # </shortcuts node>
705
+ end
706
+ end