lib/isodoc/wordconvert/wordconvertmodule.rb in isodoc-0.5.9 vs lib/isodoc/wordconvert/wordconvertmodule.rb in isodoc-0.6.0
- old
+ new
@@ -1,14 +1,23 @@
+def make_body2(body, docxml)
+ body.div **{ class: "WordSection2" } do |div2|
+ info docxml, div2
+ foreword docxml, div2
+ introduction docxml, div2
+ div2.p { |p| p << " " } # placeholder
+ end
+ section_break(body)
+end
-#require "html2doc"
-#require "liquid"
+def make_body3(body, docxml)
+ body.div **{ class: "WordSection3" } do |div3|
+ middle docxml, div3
+ footnotes div3
+ comments div3
+ end
+end
-#module IsoDoc
-#class WordConvert < Convert
-#module WordConvertModule
-#def self.included base
-#base.class_eval do
def insert_tab(out, n)
out.span **attr_code(style: "mso-tab-count:#{n}") do |span|
[1..n].each { span << "  " }
end
end
@@ -30,11 +39,10 @@
td["style"] =
td["style"].gsub(/border-bottom:[^;]+;/, "border-bottom:0pt;").
gsub(/mso-border-bottom-alt:[^;]+;/, "mso-border-bottom-alt:0pt;")
end
-#SW1 = IsoDoc::SW
SW1 = "solid windowtext".freeze
def new_fullcolspan_row(t, tfoot)
# how many columns in the table?
cols = 0
@@ -63,14 +71,12 @@
def section_break(body)
body.br **{ clear: "all", class: "section" }
end
def page_break(out)
- out.br **{
- clear: "all",
- style: "mso-special-character:line-break;page-break-before:always",
- }
+ out.br **{ clear: "all",
+ style: "mso-special-character:line-break;page-break-before:always" }
end
WORD_DT_ATTRS = {class: @note ? "Note" : nil, align: "left",
style: "margin-left:0pt;text-align:left;"}.freeze
@@ -129,123 +135,5 @@
aside.xpath(".//p").each do |a|
a.delete("class")
a.parent = dd
end
end
-
-def postprocess(result, filename, dir)
- generate_header(filename, dir)
- result = from_xhtml(cleanup(to_xhtml(result)))
- toWord(result, filename, dir)
- @files_to_delete.each { |f| system "rm #{f}" }
-end
-
-def toWord(result, filename, dir)
- result = populate_template(result, :word)
- result = from_xhtml(word_cleanup(to_xhtml(result)))
- Html2Doc.process(result, filename: filename, stylesheet: @wordstylesheet,
- header_file: "header.html", dir: dir,
- asciimathdelims: [@openmathdelim, @closemathdelim],
- liststyles: { ul: @ulstyle, ol: @olstyle })
-end
-
-def word_cleanup(docxml)
- word_preface(docxml)
- word_annex_cleanup(docxml)
- docxml
-end
-
-# force Annex h2 to be p.h2Annex, so it is not picked up by ToC
-def word_annex_cleanup(docxml)
- docxml.xpath("//h2[ancestor::*[@class = 'Section3']]").each do |h2|
- h2.name = "p"
- h2["class"] = "h2Annex"
- end
-end
-
-def word_preface(docxml)
- word_cover(docxml) if @wordcoverpage
- word_intro(docxml) if @wordintropage
-end
-
-def word_cover(docxml)
- cover = File.read(@wordcoverpage, encoding: "UTF-8")
- cover = populate_template(cover, :word)
- coverxml = to_xhtml_fragment(cover)
- docxml.at('//div[@class="WordSection1"]').children.first.previous =
- coverxml.to_xml(encoding: "US-ASCII")
-end
-
-def word_intro(docxml)
- intro = File.read(@wordintropage, encoding: "UTF-8").
- sub(/WORDTOC/, make_WordToC(docxml))
- intro = populate_template(intro, :word)
- introxml = to_xhtml_fragment(intro)
- docxml.at('//div[@class="WordSection2"]').children.first.previous =
- introxml.to_xml(encoding: "US-ASCII")
-end
-
-def generate_header(filename, _dir)
- return unless @header
- template = Liquid::Template.parse(File.read(@header, encoding: "UTF-8"))
- meta = get_metadata
- meta[:filename] = filename
- params = meta.map { |k, v| [k.to_s, v] }.to_h
- File.open("header.html", "w") do |f|
- f.write(template.render(params))
- end
- @files_to_delete << "header.html"
-end
-
-def word_toc_entry(toclevel, heading)
- bookmark = Random.rand(1000000000)
- <<~TOC
- <p class="MsoToc#{toclevel}"><span class="MsoHyperlink"><span
- lang="EN-GB" style='mso-no-proof:yes'>
- <a href="#_Toc#{bookmark}">#{heading}<span lang="EN-GB"
- class="MsoTocTextSpan">
- <span style='mso-tab-count:1 dotted'>. </span>
- </span><span lang="EN-GB" class="MsoTocTextSpan">
- <span style='mso-element:field-begin'></span></span>
- <span lang="EN-GB"
- class="MsoTocTextSpan"> PAGEREF _Toc#{bookmark} \\h </span>
- <span lang="EN-GB" class="MsoTocTextSpan"><span
- style='mso-element:field-separator'></span></span><span
- lang="EN-GB" class="MsoTocTextSpan">1</span>
- <span lang="EN-GB"
- class="MsoTocTextSpan"></span><span
- lang="EN-GB" class="MsoTocTextSpan"><span
- style='mso-element:field-end'></span></span></a></span></span></p>
-
- TOC
-end
-
-#WORD_TOC_PREFACE = <<~TOC.freeze
-WORD_TOC_PREFACE1 = <<~TOC.freeze
- <span lang="EN-GB"><span
- style='mso-element:field-begin'></span><span
- style='mso-spacerun:yes'> </span>TOC
- \\o "1-2" \\h \\z \\u <span
- style='mso-element:field-separator'></span></span>
-TOC
-
-#WORD_TOC_SUFFIX = <<~TOC.freeze
-WORD_TOC_SUFFIX1 = <<~TOC.freeze
- <p class="MsoToc1"><span lang="EN-GB"><span
- style='mso-element:field-end'></span></span><span
- lang="EN-GB"><o:p> </o:p></span></p>
-TOC
-
-def make_WordToC(docxml)
- toc = ""
- docxml.xpath("//h1 | //h2[not(ancestor::*[@class = 'Section3'])]").
- each do |h|
- toc += word_toc_entry(h.name == "h1" ? 1 : 2, header_strip(h))
- end
- toc.sub(/(<p class="MsoToc1">)/,
- #%{\\1#{WORD_TOC_PREFACE}}) + WORD_TOC_SUFFIX
- %{\\1#{WORD_TOC_PREFACE1}}) + WORD_TOC_SUFFIX1
-end
-#end
-#end
-#end
-#end