Sha256: e41b1abc4b644d97086772094fa6b72715b1d7b07f5caf3f78c548f7a891a902

Contents?: true

Size: 1.57 KB

Versions: 55

Compression:

Stored size: 1.57 KB

Contents

class Html2Doc
  class IEEE < ::Html2Doc
    def process_footnote_texts(docxml, footnotes)
      body = docxml.at("//body")
      list = body.add_child("<div style='mso-element:footnote-list'/>")
      footnotes.each_with_index do |f, i|
        if i.zero?
          fn = list.first.add_child(footnote_container_nofn(docxml, i + 1))
          f.parent = fn.first
          footnote_div_to_p_unstyled(f)
        else
          fn = list.first.add_child(footnote_container(docxml, i + 1))
          f.parent = fn.first
          footnote_div_to_p(f)
        end
      end
      footnote_cleanup(docxml)
    end

    def footnote_container_nofn(_docxml, idx)
      <<~DIV
        <div style='mso-element:footnote' id='ftn#{idx}'>
          <a style='mso-footnote-id:ftn#{idx}' href='#_ftn#{idx}'
             name='_ftnref#{idx}' title='' id='_ftnref#{idx}'></a></div>
      DIV
    end

    def footnote_div_to_p_unstyled(elem)
      if %w{div aside}.include? elem.name
        if elem.at(".//p")
          elem.replace(elem.children)
        else
          elem.name = "p"
        end
      end
    end

    def transform_footnote_text(note)
      note["id"] = ""
      note.xpath(".//div").each { |div| div.replace(div.children) }
      note.xpath(".//aside | .//p").each do |p|
        p.name = "p"
        %w(IEEEStdsCRTextReg IEEEStdsCRTextItal).include?(p["class"]) or
          p["class"] = "IEEEStdsFootnote"
      end
      note.remove
    end

    def cleanup(docxml)
      super
      docxml.xpath("//div[@class = 'Note']").each do |d|
        d.delete("class")
      end
      docxml
    end
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
metanorma-ieee-1.3.1 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.3.0 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.14 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.13 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.12 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.11 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.10 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.9 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.8 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.7 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.6 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.5 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.4 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.3 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.2 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.1 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.2.0 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.1.10 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.1.9 lib/html2doc/ieee/notes.rb
metanorma-ieee-1.1.8 lib/html2doc/ieee/notes.rb