struct Lexbor::Node
- Lexbor::Node
- Struct
- Value
- Object
Defined in:
lexbor/node.crlexbor/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
- #[](*args, **options)
- #[](*args, **options, &)
-
#[]=(key : String, value : String | Nil)
Alias for add, remove attribute node["class"] = "red" node["style"] = nil
- #[]?(*args, **options)
- #[]?(*args, **options, &)
-
#append_child(child : Node)
Add a child node to the end
-
#attribute_add(key : String, value : String, encoding = nil)
Add attribute to node
-
#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]?
- #attribute_by(slice : Slice(UInt8))
-
#attribute_remove(key : String)
Remove node attribute by key
-
#attributes
Cached Hash(String, String) of attributes allocated only if you call it
- #child
- #child!
-
#children
Children iterator iterate over all node direct children, without going deeper
-
#css(rule : String)
Css selector with string rule in scope on the current node return Lexbor::Iterator::Collection
-
#css(filter : CssFilter)
Css selector with filter in scope on the current node return Lexbor::Iterator::Collection
-
#css(arg, &)
Css select which yielding collection this allows to free collection after block call and not waiting for GC
- #each_attribute(&)
- #fetch(*args, **options)
- #fetch(*args, **options, &)
-
#flat_right
Right neighbour node from current different from
#right
method by not down to children nodes - #flat_right!
- #has_key?(*args, **options)
- #has_key?(*args, **options, &)
-
#inner_html(io)
helper method, to get inner html of the node
-
#inner_html
helper method, to get inner html of the node
-
#inner_html=(html : String)
Parse inner html as node content
-
#inner_pretty_html(io)
helper method, to get inner html of the node in pretty format
-
#inner_pretty_html
helper method, to get inner html of the node in pretty format
- #inner_text(join_with : String | Char | Nil = nil, deep = true)
-
#inner_text=(text : String)
Helper method to add inner text to node
-
#insert_after(node : Node)
Add a sibling node after this node
-
#insert_before(node : Node)
Add a sibling node before this node
-
#inspect(io : IO)
Node Inspect puts node.inspect # => Lexbor::Node(:div, {"class" => "aaa"})
- #is_comment?
- #is_tag__document?
- #is_tag__em_comment?
- #is_tag__em_doctype?
- #is_tag__end_of_file?
- #is_tag__last_entry?
- #is_tag__text?
- #is_tag__undef?
- #is_tag_a?
- #is_tag_abbr?
- #is_tag_acronym?
- #is_tag_address?
- #is_tag_altglyph?
- #is_tag_altglyphdef?
- #is_tag_altglyphitem?
- #is_tag_animatecolor?
- #is_tag_animatemotion?
- #is_tag_animatetransform?
- #is_tag_annotation_xml?
- #is_tag_applet?
- #is_tag_area?
- #is_tag_article?
- #is_tag_aside?
- #is_tag_audio?
- #is_tag_b?
- #is_tag_base?
- #is_tag_basefont?
- #is_tag_bdi?
- #is_tag_bdo?
- #is_tag_bgsound?
- #is_tag_big?
- #is_tag_blink?
- #is_tag_blockquote?
- #is_tag_body?
- #is_tag_br?
- #is_tag_button?
- #is_tag_canvas?
- #is_tag_caption?
- #is_tag_center?
- #is_tag_cite?
- #is_tag_clippath?
- #is_tag_code?
- #is_tag_col?
- #is_tag_colgroup?
- #is_tag_data?
- #is_tag_datalist?
- #is_tag_dd?
- #is_tag_del?
- #is_tag_desc?
- #is_tag_details?
- #is_tag_dfn?
- #is_tag_dialog?
- #is_tag_dir?
- #is_tag_div?
- #is_tag_dl?
- #is_tag_dt?
- #is_tag_em?
- #is_tag_embed?
- #is_tag_feblend?
- #is_tag_fecolormatrix?
- #is_tag_fecomponenttransfer?
- #is_tag_fecomposite?
- #is_tag_feconvolvematrix?
- #is_tag_fediffuselighting?
- #is_tag_fedisplacementmap?
- #is_tag_fedistantlight?
- #is_tag_fedropshadow?
- #is_tag_feflood?
- #is_tag_fefunca?
- #is_tag_fefuncb?
- #is_tag_fefuncg?
- #is_tag_fefuncr?
- #is_tag_fegaussianblur?
- #is_tag_feimage?
- #is_tag_femerge?
- #is_tag_femergenode?
- #is_tag_femorphology?
- #is_tag_feoffset?
- #is_tag_fepointlight?
- #is_tag_fespecularlighting?
- #is_tag_fespotlight?
- #is_tag_fetile?
- #is_tag_feturbulence?
- #is_tag_fieldset?
- #is_tag_figcaption?
- #is_tag_figure?
- #is_tag_font?
- #is_tag_footer?
- #is_tag_foreignobject?
- #is_tag_form?
- #is_tag_frame?
- #is_tag_frameset?
- #is_tag_glyphref?
- #is_tag_h1?
- #is_tag_h2?
- #is_tag_h3?
- #is_tag_h4?
- #is_tag_h5?
- #is_tag_h6?
- #is_tag_head?
- #is_tag_header?
- #is_tag_hgroup?
- #is_tag_hr?
- #is_tag_html?
- #is_tag_i?
- #is_tag_iframe?
- #is_tag_image?
- #is_tag_img?
- #is_tag_input?
- #is_tag_ins?
- #is_tag_isindex?
- #is_tag_kbd?
- #is_tag_keygen?
- #is_tag_label?
- #is_tag_legend?
- #is_tag_li?
- #is_tag_lineargradient?
- #is_tag_link?
- #is_tag_listing?
- #is_tag_main?
- #is_tag_malignmark?
- #is_tag_map?
- #is_tag_mark?
- #is_tag_marquee?
- #is_tag_math?
- #is_tag_menu?
- #is_tag_meta?
- #is_tag_meter?
- #is_tag_mfenced?
- #is_tag_mglyph?
- #is_tag_mi?
- #is_tag_mn?
- #is_tag_mo?
- #is_tag_ms?
- #is_tag_mtext?
- #is_tag_multicol?
- #is_tag_nav?
- #is_tag_nextid?
- #is_tag_nobr?
- #is_tag_noembed?
- #is_tag_nofollow?
- #is_tag_noframes?
- #is_tag_noindex?
- #is_tag_noscript?
- #is_tag_object?
- #is_tag_ol?
- #is_tag_optgroup?
- #is_tag_option?
- #is_tag_output?
- #is_tag_p?
- #is_tag_param?
- #is_tag_path?
- #is_tag_picture?
- #is_tag_plaintext?
- #is_tag_pre?
- #is_tag_progress?
- #is_tag_q?
- #is_tag_radialgradient?
- #is_tag_rb?
- #is_tag_rp?
- #is_tag_rt?
- #is_tag_rtc?
- #is_tag_ruby?
- #is_tag_s?
- #is_tag_samp?
- #is_tag_script?
- #is_tag_section?
- #is_tag_select?
- #is_tag_slot?
- #is_tag_small?
- #is_tag_source?
- #is_tag_spacer?
- #is_tag_span?
- #is_tag_strike?
- #is_tag_strong?
- #is_tag_style?
- #is_tag_sub?
- #is_tag_summary?
- #is_tag_sup?
- #is_tag_svg?
- #is_tag_table?
- #is_tag_tbody?
- #is_tag_td?
- #is_tag_template?
- #is_tag_textarea?
- #is_tag_textpath?
- #is_tag_tfoot?
- #is_tag_th?
- #is_tag_thead?
- #is_tag_time?
- #is_tag_title?
- #is_tag_tr?
- #is_tag_track?
- #is_tag_tt?
- #is_tag_u?
- #is_tag_ul?
- #is_tag_var?
- #is_tag_video?
- #is_tag_wbr?
- #is_tag_xmp?
- #is_text?
- #last_child
- #last_child!
- #lastest_child
- #lastest_child!
-
#left
Left node from current left means outputed in html before this
- #left!
-
#left_iterator
Left iterator iterate over all nodes from current to the root of document by moving from current to left node every time
- #next
- #next!
- #next_parent!
- #object?
- #parent
- #parent!
-
#parents
Parents iterator iterate over all node parents, from current node to root node
- #prev
- #prev!
-
#remove!
Remove node from tree
-
#right
Right node from current right means outputed in html after this
- #right!
-
#right_iterator
Right iterator iterate over all nodes from current to the end of document by moving from current to right node every time
-
#scope
Scope iterator iterate over all inner nodes of current node
-
#tag_id : Lexbor::Lib::TagIdT
Tag ID node.tag_id => Lexbor::Lib::TagIdT::LXB_TAG_DIV
-
#tag_name : String
Tag Name node.tag_name => "div"
-
#tag_sym : Symbol
Tag Symbol node.tag_sym => :div
-
#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 - #textable?
-
#to_html(io : IO, deep = true)
Convert node to html to IO deep - option, means visit children nodes or not (by default true).
-
#to_html(deep = true)
Convert node to html string deep - option, means visit children nodes or not (by default true).
-
#to_html_end
Convert end of tag to string ex: node.to_html_end # => "</div>"
-
#to_pretty_html(io : IO, deep = true)
Convert node to html string, with formatting
-
#to_pretty_html(deep = true)
Convert node to html string, with formatting
- #visible?
-
#walk_tree(level = 0, &block : Node, Int32 -> )
Walk tree similar to scope iterator, yields level and node
Constructor Detail
Class Method Detail
Instance Method Detail
Alias for add, remove attribute node["class"] = "red" node["style"] = nil
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>
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]?
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
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
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 } }
Right neighbour node from current
different from #right
method by not down to children nodes
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>
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>
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>
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>
Left iterator iterate over all nodes from current to the root of document by moving from current to left node every time
Right iterator iterate over all nodes from current to the end of document by moving from current to right node every time
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
Convert node to html to IO deep - option, means visit children nodes or not (by default 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">`
Walk tree similar to scope iterator, yields level and node