lib/isodoc/wordconvert/wordconvertmodule.rb in isodoc-0.5.8 vs lib/isodoc/wordconvert/wordconvertmodule.rb in isodoc-0.5.9
- old
+ new
@@ -69,47 +69,81 @@
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
+
def dt_parse(dt, term)
- if dt.elements.empty?
- term.p **attr_code(class: note? ? "Note" : nil,
- style: "text-align: left;") do |p|
+ term.p **attr_code(WORD_DT_ATTRS) do |p|
+ if dt.elements.empty?
p << dt.text
+ else
+ dt.children.each { |n| parse(n, p) }
end
- else
- dt.children.each { |n| parse(n, term) }
end
end
def dl_parse(node, out)
out.table **{ class: "dl" } do |v|
- node.elements.each_slice(2) do |dt, dd|
+ node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
v.tr do |tr|
tr.td **{ valign: "top", align: "left" } do |term|
dt_parse(dt, term)
end
tr.td **{ valign: "top" } do |listitem|
dd.children.each { |n| parse(n, listitem) }
end
end
end
+ dl_parse_notes(node, v)
end
end
+def dl_parse_notes(node, v)
+ return if node.elements.reject { |n| dt_dd? n }.empty?
+ v.tr do |tr|
+ tr.td **{ rowspan: 2 } do |td|
+ node.elements.reject { |n| dt_dd? n }.each { |n| parse(n, td) }
+ end
+ end
+end
+def figure_get_or_make_dl(t)
+ dl = t.at(".//table[@class = 'dl']")
+ if dl.nil?
+ t.add_child("<p><b>#{@key_lbl}</b></p><table class='dl'></table>")
+ dl = t.at(".//table[@class = 'dl']")
+ end
+ dl
+end
+def figure_aside_process(f, aside, key)
+ # get rid of footnote link, it is in diagram
+ f&.at("./a[@class='TableFootnoteRef']")&.remove
+ fnref = f.at(".//a[@class='TableFootnoteRef']")
+ tr = key.add_child("<tr></tr>").first
+ dt = tr.add_child("<td valign='top' align='left'></td>").first
+ dd = tr.add_child("<td valign='top'></td>").first
+ fnref.parent = dt
+ 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 = from_xhtml(word_cleanup(to_xhtml(result)))
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
@@ -132,20 +166,24 @@
word_cover(docxml) if @wordcoverpage
word_intro(docxml) if @wordintropage
end
def word_cover(docxml)
- cover = to_xhtml_fragment(File.read(@wordcoverpage, encoding: "UTF-8"))
+ 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 =
- cover.to_xml(encoding: "US-ASCII")
+ coverxml.to_xml(encoding: "US-ASCII")
end
def word_intro(docxml)
- intro = to_xhtml_fragment(File.read(@wordintropage, encoding: "UTF-8").
- sub(/WORDTOC/, make_WordToC(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 =
- intro.to_xml(encoding: "US-ASCII")
+ 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"))
@@ -153,9 +191,10 @@
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