struct Lexbor::Node

Defined in:

lexbor/node.cr
lexbor/node/attributes.cr
lexbor/node/css.cr
lexbor/node/helpers.cr
lexbor/node/iterators.cr
lexbor/node/navigate.cr
lexbor/node/serialization.cr
lexbor/node/tree_mutation.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(parser : Lexbor::Parser, element : Lexbor::Lib::DomElementT) #

[View source]

Class Method Detail

def self.from_raw(parser, element) #

[View source]

Instance Method Detail

def [](*args, **options) #

[View source]
def [](*args, **options, &) #

[View source]
def []=(key : String, value : String | Nil) #

Alias for add, remove attribute node["class"] = "red" node["style"] = nil


[View source]
def []?(*args, **options) #

[View source]
def []?(*args, **options, &) #

[View source]
def append_child(child : Node) #

Add a child node to the end

This inserts the child node at the end of parent node's children

document = Lexbor::Parser.new("<html><body><p>Hi!</p></body></html>")
body = document.body!
span = document.tree.create_node(:span)

body.append_child(span)
body.to_html # <body><p>Hi!</p><span></span></body>

[View source]
def attribute_add(key : String, value : String, encoding = nil) #

Add attribute to node


[View source]
def attribute_by(key : String) : String | Nil #

Find attribute by key iterate over all attributes to find it if you need to use it multiple times, better to use cached method attributes[key]?


[View source]
def attribute_by(slice : Slice(UInt8)) #

[View source]
def attribute_remove(key : String) #

Remove node attribute by key


[View source]
def attributes #

Cached Hash(String, String) of attributes allocated only if you call it


[View source]
def child #

[View source]
def child! #

[View source]
def children #

Children iterator iterate over all node direct children, without going deeper


[View source]
def css(rule : String) #

Css selector with string rule in scope on the current node return Lexbor::Iterator::Collection

Example: some_node.css("div.red").each { |node| p node } # iterate over all divs with class red in the scope of node


[View source]
def css(filter : CssFilter) #

Css selector with filter in scope on the current node return Lexbor::Iterator::Collection

Example: filter = Lexbor::CssFilter.new("div.red") some_node.css(filter).each { |node| p node } # iterator over all divs with class red in the scope of node


[View source]
def css(arg, &) #

Css select which yielding collection this allows to free collection after block call and not waiting for GC

Example: some_node.css("div.red") { |collection| collection.each { |node| p node } }


[View source]
def each_attribute(&) #

[View source]
def fetch(*args, **options) #

[View source]
def fetch(*args, **options, &) #

[View source]
def flat_right #

Right neighbour node from current different from #right method by not down to children nodes


[View source]
def flat_right! #

[View source]
def has_key?(*args, **options) #

[View source]
def has_key?(*args, **options, &) #

[View source]
def inner_html(io) #

helper method, to get inner html of the node


[View source]
def inner_html #

helper method, to get inner html of the node


[View source]
def inner_html=(html : String) #

Parse inner html as node content

document = Lexbor::Parser.new("<html><body><div></div></body></html>")
div = document.css("div").first
div.inner_html = "<a href=#>bla</a>"

document.to_html # <html><head></head><body><div><a href=\"#\">bla</a></div></body></html>

[View source]
def inner_pretty_html(io) #

helper method, to get inner html of the node in pretty format


[View source]
def inner_pretty_html #

helper method, to get inner html of the node in pretty format


[View source]
def inner_text(join_with : String | Char | Nil = nil, deep = true) #

[View source]
def inner_text=(text : String) #

Helper method to add inner text to node

document = Lexbor::Parser.new("<html><body><div></div></body></html>")
div = document.css("div").first
div.inner_text = "bla"

document.to_html # <html><head></head><body><div>bla</div></body></html>

[View source]
def insert_after(node : Node) #

Add a sibling node after this node

document = Lexbor::Parser.new("<html><body><div></div></body></html>")
div = document.css("div").first
img = document.tree.create_node(:img)

div.insert_after(img)
document.body!.to_html # <body><div></div><img></body>

[View source]
def insert_before(node : Node) #

Add a sibling node before this node

document = Lexbor::Parser.new("<html><body><main></main></body></html>")
main = document.css("main").first
header = document.tree.create_node(:header)

main.insert_before(header)
document.body!.to_html # <body><header></header><main></main></body>

[View source]
def inspect(io : IO) #

Node Inspect puts node.inspect # => Lexbor::Node(:div, {"class" => "aaa"})


[View source]
def is_comment? #

[View source]
def is_tag__document? #

[View source]
def is_tag__em_comment? #

[View source]
def is_tag__em_doctype? #

[View source]
def is_tag__end_of_file? #

[View source]
def is_tag__last_entry? #

[View source]
def is_tag__text? #

[View source]
def is_tag__undef? #

[View source]
def is_tag_a? #

[View source]
def is_tag_abbr? #

[View source]
def is_tag_acronym? #

[View source]
def is_tag_address? #

[View source]
def is_tag_altglyph? #

[View source]
def is_tag_altglyphdef? #

[View source]
def is_tag_altglyphitem? #

[View source]
def is_tag_animatecolor? #

[View source]
def is_tag_animatemotion? #

[View source]
def is_tag_animatetransform? #

[View source]
def is_tag_annotation_xml? #

[View source]
def is_tag_applet? #

[View source]
def is_tag_area? #

[View source]
def is_tag_article? #

[View source]
def is_tag_aside? #

[View source]
def is_tag_audio? #

[View source]
def is_tag_b? #

[View source]
def is_tag_base? #

[View source]
def is_tag_basefont? #

[View source]
def is_tag_bdi? #

[View source]
def is_tag_bdo? #

[View source]
def is_tag_bgsound? #

[View source]
def is_tag_big? #

[View source]
def is_tag_blink? #

[View source]
def is_tag_blockquote? #

[View source]
def is_tag_body? #

[View source]
def is_tag_br? #

[View source]
def is_tag_button? #

[View source]
def is_tag_canvas? #

[View source]
def is_tag_caption? #

[View source]
def is_tag_center? #

[View source]
def is_tag_cite? #

[View source]
def is_tag_clippath? #

[View source]
def is_tag_code? #

[View source]
def is_tag_col? #

[View source]
def is_tag_colgroup? #

[View source]
def is_tag_data? #

[View source]
def is_tag_datalist? #

[View source]
def is_tag_dd? #

[View source]
def is_tag_del? #

[View source]
def is_tag_desc? #

[View source]
def is_tag_details? #

[View source]
def is_tag_dfn? #

[View source]
def is_tag_dialog? #

[View source]
def is_tag_dir? #

[View source]
def is_tag_div? #

[View source]
def is_tag_dl? #

[View source]
def is_tag_dt? #

[View source]
def is_tag_em? #

[View source]
def is_tag_embed? #

[View source]
def is_tag_feblend? #

[View source]
def is_tag_fecolormatrix? #

[View source]
def is_tag_fecomponenttransfer? #

[View source]
def is_tag_fecomposite? #

[View source]
def is_tag_feconvolvematrix? #

[View source]
def is_tag_fediffuselighting? #

[View source]
def is_tag_fedisplacementmap? #

[View source]
def is_tag_fedistantlight? #

[View source]
def is_tag_fedropshadow? #

[View source]
def is_tag_feflood? #

[View source]
def is_tag_fefunca? #

[View source]
def is_tag_fefuncb? #

[View source]
def is_tag_fefuncg? #

[View source]
def is_tag_fefuncr? #

[View source]
def is_tag_fegaussianblur? #

[View source]
def is_tag_feimage? #

[View source]
def is_tag_femerge? #

[View source]
def is_tag_femergenode? #

[View source]
def is_tag_femorphology? #

[View source]
def is_tag_feoffset? #

[View source]
def is_tag_fepointlight? #

[View source]
def is_tag_fespecularlighting? #

[View source]
def is_tag_fespotlight? #

[View source]
def is_tag_fetile? #

[View source]
def is_tag_feturbulence? #

[View source]
def is_tag_fieldset? #

[View source]
def is_tag_figcaption? #

[View source]
def is_tag_figure? #

[View source]
def is_tag_font? #

[View source]
def is_tag_footer? #

[View source]
def is_tag_foreignobject? #

[View source]
def is_tag_form? #

[View source]
def is_tag_frame? #

[View source]
def is_tag_frameset? #

[View source]
def is_tag_glyphref? #

[View source]
def is_tag_h1? #

[View source]
def is_tag_h2? #

[View source]
def is_tag_h3? #

[View source]
def is_tag_h4? #

[View source]
def is_tag_h5? #

[View source]
def is_tag_h6? #

[View source]
def is_tag_head? #

[View source]
def is_tag_header? #

[View source]
def is_tag_hgroup? #

[View source]
def is_tag_hr? #

[View source]
def is_tag_html? #

[View source]
def is_tag_i? #

[View source]
def is_tag_iframe? #

[View source]
def is_tag_image? #

[View source]
def is_tag_img? #

[View source]
def is_tag_input? #

[View source]
def is_tag_ins? #

[View source]
def is_tag_isindex? #

[View source]
def is_tag_kbd? #

[View source]
def is_tag_keygen? #

[View source]
def is_tag_label? #

[View source]
def is_tag_legend? #

[View source]
def is_tag_li? #

[View source]
def is_tag_lineargradient? #

[View source]
def is_tag_link? #

[View source]
def is_tag_listing? #

[View source]
def is_tag_main? #

[View source]
def is_tag_malignmark? #

[View source]
def is_tag_map? #

[View source]
def is_tag_mark? #

[View source]
def is_tag_marquee? #

[View source]
def is_tag_math? #

[View source]
def is_tag_menu? #

[View source]
def is_tag_meta? #

[View source]
def is_tag_meter? #

[View source]
def is_tag_mfenced? #

[View source]
def is_tag_mglyph? #

[View source]
def is_tag_mi? #

[View source]
def is_tag_mn? #

[View source]
def is_tag_mo? #

[View source]
def is_tag_ms? #

[View source]
def is_tag_mtext? #

[View source]
def is_tag_multicol? #

[View source]
def is_tag_nav? #

[View source]
def is_tag_nextid? #

[View source]
def is_tag_nobr? #

[View source]
def is_tag_noembed? #

[View source]
def is_tag_nofollow? #

[View source]
def is_tag_noframes? #

[View source]
def is_tag_noindex? #

[View source]
def is_tag_noscript? #

[View source]
def is_tag_object? #

[View source]
def is_tag_ol? #

[View source]
def is_tag_optgroup? #

[View source]
def is_tag_option? #

[View source]
def is_tag_output? #

[View source]
def is_tag_p? #

[View source]
def is_tag_param? #

[View source]
def is_tag_path? #

[View source]
def is_tag_picture? #

[View source]
def is_tag_plaintext? #

[View source]
def is_tag_pre? #

[View source]
def is_tag_progress? #

[View source]
def is_tag_q? #

[View source]
def is_tag_radialgradient? #

[View source]
def is_tag_rb? #

[View source]
def is_tag_rp? #

[View source]
def is_tag_rt? #

[View source]
def is_tag_rtc? #

[View source]
def is_tag_ruby? #

[View source]
def is_tag_s? #

[View source]
def is_tag_samp? #

[View source]
def is_tag_script? #

[View source]
def is_tag_section? #

[View source]
def is_tag_select? #

[View source]
def is_tag_slot? #

[View source]
def is_tag_small? #

[View source]
def is_tag_source? #

[View source]
def is_tag_spacer? #

[View source]
def is_tag_span? #

[View source]
def is_tag_strike? #

[View source]
def is_tag_strong? #

[View source]
def is_tag_style? #

[View source]
def is_tag_sub? #

[View source]
def is_tag_summary? #

[View source]
def is_tag_sup? #

[View source]
def is_tag_svg? #

[View source]
def is_tag_table? #

[View source]
def is_tag_tbody? #

[View source]
def is_tag_td? #

[View source]
def is_tag_template? #

[View source]
def is_tag_textarea? #

[View source]
def is_tag_textpath? #

[View source]
def is_tag_tfoot? #

[View source]
def is_tag_th? #

[View source]
def is_tag_thead? #

[View source]
def is_tag_time? #

[View source]
def is_tag_title? #

[View source]
def is_tag_tr? #

[View source]
def is_tag_track? #

[View source]
def is_tag_tt? #

[View source]
def is_tag_u? #

[View source]
def is_tag_ul? #

[View source]
def is_tag_var? #

[View source]
def is_tag_video? #

[View source]
def is_tag_wbr? #

[View source]
def is_tag_xmp? #

[View source]
def is_text? #

[View source]
def last_child #

[View source]
def last_child! #

[View source]
def lastest_child #

[View source]
def lastest_child! #

[View source]
def left #

Left node from current left means outputed in html before this


[View source]
def left! #

[View source]
def left_iterator #

Left iterator iterate over all nodes from current to the root of document by moving from current to left node every time


[View source]
def next #

[View source]
def next! #

[View source]
def next_parent! #

[View source]
def object? #

[View source]
def parent #

[View source]
def parent! #

[View source]
def parents #

Parents iterator iterate over all node parents, from current node to root node


[View source]
def prev #

[View source]
def prev! #

[View source]
def remove! #

Remove node from tree


[View source]
def right #

Right node from current right means outputed in html after this


[View source]
def right! #

[View source]
def right_iterator #

Right iterator iterate over all nodes from current to the end of document by moving from current to right node every time


[View source]
def scope #

Scope iterator iterate over all inner nodes of current node


[View source]
def tag_id : Lexbor::Lib::TagIdT #

Tag ID node.tag_id => Lexbor::Lib::TagIdT::LXB_TAG_DIV


[View source]
def tag_name : String #

Tag Name node.tag_name => "div"


[View source]
def tag_sym : Symbol #

Tag Symbol node.tag_sym => :div


[View source]
def tag_text #

Tag Text Direct text content of node present only on LXB_TAG__TEXT, LXB_TAG_STYLE, LXB_TAG__EM_COMMENT nodes (node.textable?) for other nodes, you should call #inner_text method


[View source]
def textable? #

[View source]
def to_html(io : IO, deep = true) #

Convert node to html to IO deep - option, means visit children nodes or not (by default true).


[View source]
def to_html(deep = true) #

Convert node to html string deep - option, means visit children nodes or not (by default true).

Example:

parser = Lexbor::Parser.new("<html><body><div class=AAA style='color:red'>Haha <span>11</span></div></body></html>")
node = parser.nodes(:div).first
node.to_html              # => `<div class="AAA" style="color:red">Haha <span>11</span></div>`
node.to_html(deep: false) # => `<div class="AAA" style="color:red">`

[View source]
def to_html_end #

Convert end of tag to string ex: node.to_html_end # => "</div>"


[View source]
def to_pretty_html(io : IO, deep = true) #

Convert node to html string, with formatting


[View source]
def to_pretty_html(deep = true) #

Convert node to html string, with formatting


[View source]
def visible? #

[View source]
def walk_tree(level = 0, &block : Node, Int32 -> ) #

Walk tree similar to scope iterator, yields level and node


[View source]