Sha256: 2ffbfeb93ae1119f03713bd219737ea6724769e11b4caaf7acb9033ada79d77c

Contents?: true

Size: 1.36 KB

Versions: 2

Compression:

Stored size: 1.36 KB

Contents

module IsoDoc
  module Itu
    module BaseConvert
      def cleanup(docxml)
        super
        term_cleanup(docxml)
        refs_cleanup(docxml)
        title_cleanup(docxml)
      end

      def title_cleanup(docxml)
        docxml.xpath("//h1[@class = 'RecommendationAnnex']").each do |h|
          h.name = "p"
          h["class"] = "h1Annex"
        end
        docxml
      end

      def term_cleanup(docxml)
        term_cleanup1(docxml)
        term_cleanup2(docxml)
        docxml
      end

      def term_cleanup1(docxml)
        docxml.xpath("//p[@class = 'Terms']").each do |d|
          h2 = d.at("./preceding-sibling::*[@class = 'TermNum'][1]")
          d.children.first.previous = "<b>#{h2.children.to_xml}</b>&#xa0;"
          d["id"] = h2["id"]
          h2.remove
        end
      end

      def term_cleanup2(docxml)
        docxml.xpath("//p[@class = 'TermNum']").each do |d|
          (d1 = d.next_element and d1.name == "p") or next
          d1.children.each { |e| e.parent = d }
          d1.remove
        end
      end

      def refs_cleanup(docxml)
        docxml.xpath("//tx[following-sibling::tx]").each do |tx|
          tx << tx.next_element.remove.children
        end
        docxml.xpath("//tx").each do |tx|
          tx.name = "td"
          tx["colspan"] = "2"
          tx.wrap("<tr></tr>")
        end
        docxml
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
metanorma-itu-2.5.6 lib/isodoc/itu/cleanup.rb
metanorma-itu-2.5.5 lib/isodoc/itu/cleanup.rb