lib/html2doc/lists.rb in html2doc-1.3.1 vs lib/html2doc/lists.rb in html2doc-1.4.0

- old
+ new

@@ -1,23 +1,23 @@ require "uuidtools" require "asciimath" require "htmlentities" require "nokogiri" -module Html2Doc - def self.style_list(elem, level, liststyle, listnumber) +class Html2Doc + def style_list(elem, level, liststyle, listnumber) return unless liststyle if elem["style"] elem["style"] += ";" else elem["style"] = "" end elem["style"] += "mso-list:#{liststyle} level#{level} lfo#{listnumber};" end - def self.list_add1(elem, liststyles, listtype, level) + def list_add1(elem, liststyles, listtype, level) if %i[ul ol].include? listtype list_add(elem.xpath(".//ul") - elem.xpath(".//ul//ul | .//ol//ul"), liststyles, :ul, level + 1) list_add(elem.xpath(".//ol") - elem.xpath(".//ul//ol | .//ol//ol"), liststyles, :ol, level + 1) @@ -27,11 +27,11 @@ list_add(elem.xpath(".//ol") - elem.xpath(".//ul//ol | .//ol//ol"), liststyles, listtype, level + 1) end end - def self.list_add(xpath, liststyles, listtype, level) + def list_add(xpath, liststyles, listtype, level) xpath.each_with_index do |l, _i| @listnumber += 1 if level == 1 l["seen"] = true if level == 1 l["id"] ||= UUIDTools::UUID.random_create (l.xpath(".//li") - l.xpath(".//ol//li | .//ul//li")).each do |li| @@ -44,11 +44,11 @@ list_add1(li.parent, liststyles, listtype, level - 1) end end end - def self.list2para(list) + def list2para(list) return if list.xpath("./li").empty? list.xpath("./li").first["class"] ||= "MsoListParagraphCxSpFirst" list.xpath("./li").last["class"] ||= "MsoListParagraphCxSpLast" list.xpath("./li/p").each { |p| p["class"] ||= "MsoListParagraphCxSpMiddle" } @@ -61,11 +61,11 @@ list.replace(list.children) end TOPLIST = "[not(ancestor::ul) and not(ancestor::ol)]".freeze - def self.lists1(docxml, liststyles, style) + def lists1(docxml, liststyles, style) case style when :ul then list_add(docxml.xpath("//ul[not(@class)]#{TOPLIST}"), liststyles, :ul, 1) when :ol then list_add(docxml.xpath("//ol[not(@class)]#{TOPLIST}"), liststyles, :ol, 1) @@ -74,11 +74,11 @@ "//ul[@class = '#{style}']#{TOPLIST}"), liststyles, style, 1) end end - def self.lists_unstyled(docxml, liststyles) + def lists_unstyled(docxml, liststyles) liststyles.has_key?(:ul) and list_add(docxml.xpath("//ul#{TOPLIST}[not(@seen)]"), liststyles, :ul, 1) liststyles.has_key?(:ol) and list_add(docxml.xpath("//ol#{TOPLIST}[not(@seen)]"), @@ -86,10 +86,10 @@ docxml.xpath("//ul[@seen] | //ol[@seen]").each do |l| l.delete("seen") end end - def self.lists(docxml, liststyles) + def lists(docxml, liststyles) return if liststyles.nil? @listnumber = 0 liststyles.each_key { |k| lists1(docxml, liststyles, k) } lists_unstyled(docxml, liststyles)