require_relative "./table.rb" module IsoDoc::WordFunction module Body def define_head(head, filename, _dir) head.style do |style| loc = File.join(File.dirname(__FILE__), "..", "base_style", "metanorma_word.scss") stylesheet = File.read(loc, encoding: "utf-8") style.comment "\n#{stylesheet}\n" end super end def body_attr { lang: "EN-US", link: "blue", vlink: "#954F72" } end def make_body1(body, _docxml) FileUtils.rm_rf tmpimagedir FileUtils.mkdir tmpimagedir body.div **{ class: "WordSection1" } do |div1| div1.p { |p| p << " " } # placeholder end section_break(body) end def make_body2(body, docxml) body.div **{ class: "WordSection2" } do |div2| boilerplate docxml, div2 abstract docxml, div2 foreword docxml, div2 introduction docxml, div2 preface docxml, div2 acknowledgements docxml, div2 div2.p { |p| p << " " } # placeholder end section_break(body) end def make_body3(body, docxml) body.div **{ class: "WordSection3" } do |div3| middle docxml, div3 footnotes div3 comments div3 end end def insert_tab(out, n) out.span **attr_code(style: "mso-tab-count:#{n}") do |span| [1..n].each { span << " " } end end def para_class(_node) classtype = nil classtype = "Note" if @note classtype = "MsoCommentText" if in_comment classtype = "Sourcecode" if @annotation classtype end def para_parse(node, out) out.p **attr_code(para_attrs(node)) do |p| unless @termdomain.empty? p << "<#{@termdomain}> " @termdomain = "" end node.children.each { |n| parse(n, p) unless n.name == "note" } end node.xpath(ns("./note")).each { |n| parse(n, out) } end def section_break(body) body.p do |p| p.br **{ clear: "all", class: "section" } end end def page_break(out) out.p do |p| p.br **{ clear: "all", style: "mso-special-character:line-break;"\ "page-break-before:always" } end end def pagebreak_parse(node, out) return page_break(out) if node["orientation"].nil? out.p do |p| p.br **{clear: "all", class: "section", orientation: node["orientation"] } end end WORD_DT_ATTRS = {class: @note ? "Note" : nil, align: "left", style: "margin-left:0pt;text-align:left;"}.freeze def dt_parse(dt, term) 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 end end def dl_parse(node, out) out.table **{ class: "dl" } do |v| 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 **{ colspan: 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("
#{@key_lbl}