Sha256: 41e18497f3394da1ffd0de6a13687581588eed6c4a6b010ffbd1dc9bea0f5446

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require "uuidtools"
require "asciimath"
require "htmlentities"
require "nokogiri"
require "xml/xslt"
require "pp"

module Html2Doc
  def self.style_list(li, level, listno)
    return unless listno
    if li["style"]
      li["style"] += ";"
    else
      li["style"] = ""
    end
    # I don't know what the lfo-n attribute is. I doubt Micro$oft now does either.
    li["style"] += "mso-list:#{listno} level#{level} lfo1;"
  end

  def self.list_add(xpath, liststyles, listtype, level)
    xpath.each do |list|
      (list.xpath(".//li") - list.xpath(".//ol//li | .//ul//li")).each do |li|
        style_list(li, level, liststyles[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)
      end
    end
  end

  def self.lists(docxml, liststyles)
    return if liststyles.nil?
    if liststyles.has_key?(:ul)
      list_add(docxml.xpath("//ul[not(ancestor::ul) and not(ancestor::ol)]"), liststyles, :ul, 1)
    end
    if liststyles.has_key?(:ol)
      list_add(docxml.xpath("//ol[not(ancestor::ul) and not(ancestor::ol)]"), liststyles, :ol, 1)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
html2doc-0.6.5 lib/html2doc/lists.rb