struct

Myhtml::Node

Inherits Struct < Value < Object

Constructors

new(tree : Myhtml::Tree, raw_node : Pointer(Myhtml::Lib::MyhtmlTreeNodeT))
Source

Class methods

from_raw(tree, raw_node)
Source

Instance methods

[]=(key : String, value : String | Nil)

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

Source
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 = Myhtml::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>
Source
attribute_add(key : String, value : String, encoding = nil)

Add attribute to node

Source
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]?

Source
attribute_by(slice : Slice(UInt8))
Source
attribute_remove(key : String)

Remove node attribute by key

Source
attributes

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

Source
child
Source
child!
Source
children

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

Source
css(rule : String)

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

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

Source
css(filter : CssFilter)

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

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

Source
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 } }

Source
data

Node Storage get stored Void* data

Source
data=(d : Pointer(Void))

Node Storage set Void* data related to this node

Source
each_attribute
Source
flat_right

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

Source
flat_right!
Source
inner_text(join_with : String | Char | Nil = nil, deep = true)
Source
inner_text=(text : String)

Helper method to add inner text to node

document = Myhtml::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>
Source
insert_after(node : Node)

Add a sibling node after this node

document = Myhtml::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>
Source
insert_before(node : Node)

Add a sibling node before this node

document = Myhtml::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>
Source
inspect(io : IO)

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

Source
is_tag__comment?
Source
is_tag__doctype?
Source
is_tag__end_of_file?
Source
is_tag__text?
Source
is_tag__undef?
Source
is_tag_a?
Source
is_tag_abbr?
Source
is_tag_acronym?
Source
is_tag_address?
Source
is_tag_altglyph?
Source
is_tag_altglyphdef?
Source
is_tag_altglyphitem?
Source
is_tag_animate?
Source
is_tag_animatecolor?
Source
is_tag_animatemotion?
Source
is_tag_animatetransform?
Source
is_tag_annotation_xml?
Source
is_tag_applet?
Source
is_tag_area?
Source
is_tag_article?
Source
is_tag_aside?
Source
is_tag_audio?
Source
is_tag_b?
Source
is_tag_base?
Source
is_tag_basefont?
Source
is_tag_bdi?
Source
is_tag_bdo?
Source
is_tag_bgsound?
Source
is_tag_big?
Source
is_tag_blockquote?
Source
is_tag_body?
Source
is_tag_br?
Source
is_tag_button?
Source
is_tag_canvas?
Source
is_tag_caption?
Source
is_tag_center?
Source
is_tag_circle?
Source
is_tag_cite?
Source
is_tag_clippath?
Source
is_tag_code?
Source
is_tag_col?
Source
is_tag_colgroup?
Source
is_tag_color_profile?
Source
is_tag_command?
Source
is_tag_comment?
Source
is_tag_cursor?
Source
is_tag_datalist?
Source
is_tag_dd?
Source
is_tag_defs?
Source
is_tag_del?
Source
is_tag_desc?
Source
is_tag_details?
Source
is_tag_dfn?
Source
is_tag_dialog?
Source
is_tag_dir?
Source
is_tag_div?
Source
is_tag_dl?
Source
is_tag_dt?
Source
is_tag_ellipse?
Source
is_tag_em?
Source
is_tag_embed?
Source
is_tag_feblend?
Source
is_tag_fecolormatrix?
Source
is_tag_fecomponenttransfer?
Source
is_tag_fecomposite?
Source
is_tag_feconvolvematrix?
Source
is_tag_fediffuselighting?
Source
is_tag_fedisplacementmap?
Source
is_tag_fedistantlight?
Source
is_tag_fedropshadow?
Source
is_tag_feflood?
Source
is_tag_fefunca?
Source
is_tag_fefuncb?
Source
is_tag_fefuncg?
Source
is_tag_fefuncr?
Source
is_tag_fegaussianblur?
Source
is_tag_feimage?
Source
is_tag_femerge?
Source
is_tag_femergenode?
Source
is_tag_femorphology?
Source
is_tag_feoffset?
Source
is_tag_fepointlight?
Source
is_tag_fespecularlighting?
Source
is_tag_fespotlight?
Source
is_tag_fetile?
Source
is_tag_feturbulence?
Source
is_tag_fieldset?
Source
is_tag_figcaption?
Source
is_tag_figure?
Source
is_tag_filter?
Source
is_tag_first_entry?
Source
is_tag_font?
Source
is_tag_font_face?
Source
is_tag_font_face_format?
Source
is_tag_font_face_name?
Source
is_tag_font_face_src?
Source
is_tag_font_face_uri?
Source
is_tag_foreignobject?
Source
is_tag_form?
Source
is_tag_frame?
Source
is_tag_frameset?
Source
is_tag_g?
Source
is_tag_glyph?
Source
is_tag_glyphref?
Source
is_tag_h1?
Source
is_tag_h2?
Source
is_tag_h3?
Source
is_tag_h4?
Source
is_tag_h5?
Source
is_tag_h6?
Source
is_tag_head?
Source
is_tag_header?
Source
is_tag_hgroup?
Source
is_tag_hkern?
Source
is_tag_hr?
Source
is_tag_html?
Source
is_tag_i?
Source
is_tag_iframe?
Source
is_tag_image?
Source
is_tag_img?
Source
is_tag_input?
Source
is_tag_ins?
Source
is_tag_isindex?
Source
is_tag_kbd?
Source
is_tag_keygen?
Source
is_tag_label?
Source
is_tag_last_entry?
Source
is_tag_legend?
Source
is_tag_li?
Source
is_tag_line?
Source
is_tag_lineargradient?
Source
is_tag_listing?
Source
is_tag_maction?
Source
is_tag_main?
Source
is_tag_maligngroup?
Source
is_tag_malignmark?
Source
is_tag_map?
Source
is_tag_mark?
Source
is_tag_marker?
Source
is_tag_marquee?
Source
is_tag_mask?
Source
is_tag_math?
Source
is_tag_menclose?
Source
is_tag_menu?
Source
is_tag_menuitem?
Source
is_tag_merror?
Source
is_tag_meta?
Source
is_tag_metadata?
Source
is_tag_meter?
Source
is_tag_mfenced?
Source
is_tag_mfrac?
Source
is_tag_mglyph?
Source
is_tag_mi?
Source
is_tag_missing_glyph?
Source
is_tag_mlabeledtr?
Source
is_tag_mlongdiv?
Source
is_tag_mmultiscripts?
Source
is_tag_mn?
Source
is_tag_mo?
Source
is_tag_mover?
Source
is_tag_mpadded?
Source
is_tag_mpath?
Source
is_tag_mphantom?
Source
is_tag_mroot?
Source
is_tag_mrow?
Source
is_tag_ms?
Source
is_tag_mscarries?
Source
is_tag_mscarry?
Source
is_tag_msgroup?
Source
is_tag_msline?
Source
is_tag_mspace?
Source
is_tag_msqrt?
Source
is_tag_msrow?
Source
is_tag_mstack?
Source
is_tag_mstyle?
Source
is_tag_msub?
Source
is_tag_msubsup?
Source
is_tag_msup?
Source
is_tag_mtext?
Source
is_tag_nav?
Source
is_tag_nobr?
Source
is_tag_noembed?
Source
is_tag_nofollow?
Source
is_tag_noframes?
Source
is_tag_noindex?
Source
is_tag_noscript?
Source
is_tag_object?
Source
is_tag_ol?
Source
is_tag_optgroup?
Source
is_tag_option?
Source
is_tag_output?
Source
is_tag_p?
Source
is_tag_param?
Source
is_tag_path?
Source
is_tag_pattern?
Source
is_tag_plaintext?
Source
is_tag_polygon?
Source
is_tag_polyline?
Source
is_tag_pre?
Source
is_tag_progress?
Source
is_tag_q?
Source
is_tag_radialgradient?
Source
is_tag_rb?
Source
is_tag_rect?
Source
is_tag_rp?
Source
is_tag_rt?
Source
is_tag_rtc?
Source
is_tag_ruby?
Source
is_tag_s?
Source
is_tag_samp?
Source
is_tag_script?
Source
is_tag_section?
Source
is_tag_select?
Source
is_tag_set?
Source
is_tag_small?
Source
is_tag_source?
Source
is_tag_span?
Source
is_tag_stop?
Source
is_tag_strike?
Source
is_tag_strong?
Source
is_tag_style?
Source
is_tag_sub?
Source
is_tag_summary?
Source
is_tag_sup?
Source
is_tag_svg?
Source
is_tag_switch?
Source
is_tag_symbol?
Source
is_tag_table?
Source
is_tag_tbody?
Source
is_tag_td?
Source
is_tag_template?
Source
is_tag_text?
Source
is_tag_textarea?
Source
is_tag_textpath?
Source
is_tag_tfoot?
Source
is_tag_th?
Source
is_tag_thead?
Source
is_tag_time?
Source
is_tag_title?
Source
is_tag_tr?
Source
is_tag_track?
Source
is_tag_tref?
Source
is_tag_tspan?
Source
is_tag_tt?
Source
is_tag_u?
Source
is_tag_ul?
Source
is_tag_use?
Source
is_tag_var?
Source
is_tag_video?
Source
is_tag_view?
Source
is_tag_vkern?
Source
is_tag_wbr?
Source
is_tag_xmp?
Source
is_text?
Source
last_child
Source
last_child!
Source
lastest_child
Source
lastest_child!
Source
left

Left node from current left means outputed in html before this

Source
left!
Source
left_iterator

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

Source
next
Source
next!
Source
next_parent!
Source
object?
Source
parent
Source
parent!
Source
parents

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

Source
prev
Source
prev!
Source
remove!

Remove node from tree

Source
right

Right node from current right means outputed in html after this

Source
right!
Source
right_iterator

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

Source
scope

Scope iterator iterate over all inner nodes of current node

Source
tag_id

Tag ID node.tag_id => Myhtml::Lib::MyhtmlTags::MyHTML_TAG_DIV

Source
tag_name

Tag Name node.tag_name => "div"

Source
tag_sym

Tag Symbol node.tag_sym => :div

Source
tag_text

Tag Text Direct text content of node present only on MyHTML_TAG__TEXT, MyHTML_TAG_STYLE, MyHTML_TAG__COMMENT nodes (node.textable?) for other nodes, you should call inner_text method

Source
textable?
Source
to_html(io : IO, deep = true)

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

Source
to_html(deep = true)

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

Example:

parser = Myhtml::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">`
Source
to_html_end

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

"

Source
to_pretty_html(io : IO)

Convert node to html string, with formatting

Source
to_pretty_html

Convert node to html string, with formatting

Source
visible?
Source
walk_tree(level = 0, &block : Node, Int32 -> )

Walk tree similar to scope iterator, yields level and node

Source