lib/hatemile/util/html/nokogiri/nokogiri_html_dom_element.rb
##
# Convert a Nokogiri Node to a HTML code.
#
# @param node [Nokogiri::XML::Node] The Nokogiri Node.
# @return [String] The HTML code of the Nokogiri Node.
Convert a Nokogiri Node to a HTML code.
Convert a Nokogiri Node to a HTML code .
def to_string(node)
            string = ''
            if node.element?
              string += "<#{node.name.downcase}"
              node.attributes.each do |attribute, value|
                string += " #{attribute}=\"#{value}\""
              end
              string += if node.children.empty? && self_closing_tag?(node.name)
                          ' />'
                        else
                          '>'
                        end
            elsif node.comment?
              string += node.to_s
            elsif node.cdata?
              string += node.to_s
            elsif node.html?
              document = node.to_s
              string += document.split("\n")[0] + "\n"
            elsif node.text?
              string += node.text
            end
            node.children.each do |child|
              string += to_string(child)
            end
            if node.element? &&
               !(node.children.empty? && self_closing_tag?(node.name))
              string += "</#{node.name.downcase}>"
            end
            string
          end
def to_string ( node ) string = '' if node . element? string += "<#{node.name.downcase}" node . attributes . each do | attribute , value | string += " #{attribute}=\"#{value}\"" end string += if node . children . empty? && self_closing_tag? ( node . name ) ' />' else '>' end elsif node . comment? string += node . to_s elsif node . cdata? string += node . to_s elsif node . html? document = node . to_s string += document . split ( "\n" ) [ 0 ] + "\n" elsif node . text? string += node . text end node . children . each do | child | string += to_string ( child ) end if node . element? && ! ( node . children . empty? && self_closing_tag? ( node . name ) ) string += "</#{node.name.downcase}>" end string end
Convert a Nokogiri Node to a HTML code.
Convert a Nokogiri Node to a HTML code .
The HTML code of the Nokogiri Node.
The HTML code of the Nokogiri Node .
String
node
The Nokogiri Node.
The Nokogiri Node .