lib/html2doc/lists.rb in html2doc-1.0.0 vs lib/html2doc/lists.rb in html2doc-1.0.1
- old
+ new
@@ -1,10 +1,10 @@
require "uuidtools"
require "asciimath"
require "htmlentities"
require "nokogiri"
-require "pp"
+require "uuidtools"
module Html2Doc
def self.style_list(li, level, liststyle, listnumber)
return unless liststyle
if li["style"]
@@ -13,26 +13,35 @@
li["style"] = ""
end
li["style"] += "mso-list:#{liststyle} level#{level} lfo#{listnumber};"
end
- def self.list_add(xpath, liststyles, listtype, level)
- xpath.each_with_index do |list, i|
- @listnumber += 1 if level == 1
- list["seen"] = true if level == 1
- (list.xpath(".//li") - list.xpath(".//ol//li | .//ul//li")).each do |li|
- style_list(li, level, liststyles[listtype], @listnumber)
- if [:ul, :ol].include? listtype
+ def self.list_add1(li, liststyles, listtype, level)
+ if [:ul, :ol].include? listtype
list_add(li.xpath(".//ul") - li.xpath(".//ul//ul | .//ol//ul"),
liststyles, :ul, level + 1)
list_add(li.xpath(".//ol") - li.xpath(".//ul//ol | .//ol//ol"),
liststyles, :ol, level + 1)
else
list_add(li.xpath(".//ul") - li.xpath(".//ul//ul | .//ol//ul"),
liststyles, listtype, level + 1)
list_add(li.xpath(".//ol") - li.xpath(".//ul//ol | .//ol//ol"),
liststyles, listtype, level + 1)
end
+ end
+
+ def self.list_add(xpath, liststyles, listtype, level)
+ xpath.each_with_index do |list, i|
+ @listnumber += 1 if level == 1
+ list["seen"] = true if level == 1
+ list["id"] ||= UUIDTools::UUID.random_create
+ (list.xpath(".//li") - list.xpath(".//ol//li | .//ul//li")).each do |li|
+ style_list(li, level, liststyles[listtype], @listnumber)
+ list_add1(li, liststyles, listtype, level)
+ end
+ list.xpath(".//ul[not(ancestor::li/ancestor::*/@id = '#{list['id']}')] | "\
+ ".//ol[not(ancestor::li/ancestor::*/@id = '#{list['id']}')]").each do |li|
+ list_add1(li.parent, liststyles, listtype, level-1)
end
end
end
def self.list2para(u)