isodoc 1.5.2 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +1 -1
  3. data/.rubocop.yml +6 -2
  4. data/Gemfile +2 -2
  5. data/bin/rspec +1 -2
  6. data/isodoc.gemspec +11 -11
  7. data/lib/isodoc/base_style/all.css +7 -0
  8. data/lib/isodoc/base_style/metanorma_word.css +7 -0
  9. data/lib/isodoc/base_style/metanorma_word.scss +8 -0
  10. data/lib/isodoc/base_style/reset.css +7 -0
  11. data/lib/isodoc/base_style/reset.scss +9 -0
  12. data/lib/isodoc/base_style/scripts.html +187 -0
  13. data/lib/isodoc/class_utils.rb +6 -5
  14. data/lib/isodoc/convert.rb +30 -17
  15. data/lib/isodoc/css.rb +42 -28
  16. data/lib/isodoc/function/blocks.rb +15 -4
  17. data/lib/isodoc/function/blocks_example_note.rb +2 -2
  18. data/lib/isodoc/function/cleanup.rb +1 -2
  19. data/lib/isodoc/function/inline.rb +31 -10
  20. data/lib/isodoc/function/references.rb +1 -1
  21. data/lib/isodoc/function/to_word_html.rb +19 -8
  22. data/lib/isodoc/function/utils.rb +41 -38
  23. data/lib/isodoc/gem_tasks.rb +30 -31
  24. data/lib/isodoc/html_convert.rb +4 -4
  25. data/lib/isodoc/html_function/postprocess.rb +35 -76
  26. data/lib/isodoc/html_function/postprocess_footnotes.rb +59 -0
  27. data/lib/isodoc/i18n.rb +20 -20
  28. data/lib/isodoc/pdf_convert.rb +1 -3
  29. data/lib/isodoc/presentation_function/block.rb +26 -11
  30. data/lib/isodoc/presentation_function/inline.rb +44 -38
  31. data/lib/isodoc/presentation_xml_convert.rb +1 -1
  32. data/lib/isodoc/version.rb +1 -1
  33. data/lib/isodoc/word_function/footnotes.rb +22 -15
  34. data/lib/isodoc/word_function/inline.rb +6 -0
  35. data/lib/isodoc/word_function/postprocess.rb +16 -6
  36. data/lib/isodoc/xref.rb +10 -11
  37. data/lib/isodoc/xref/xref_counter.rb +31 -15
  38. data/lib/isodoc/xref/xref_gen.rb +28 -22
  39. data/lib/isodoc/xref/xref_sect_gen.rb +22 -20
  40. data/lib/isodoc/xslfo_convert.rb +36 -25
  41. data/spec/assets/html_override.css +1 -0
  42. data/spec/assets/word_override.css +1 -0
  43. data/spec/isodoc/blocks_spec.rb +2599 -2503
  44. data/spec/isodoc/cleanup_spec.rb +1107 -1109
  45. data/spec/isodoc/footnotes_spec.rb +1 -16
  46. data/spec/isodoc/i18n_spec.rb +984 -972
  47. data/spec/isodoc/inline_spec.rb +34 -0
  48. data/spec/isodoc/lists_spec.rb +316 -315
  49. data/spec/isodoc/postproc_spec.rb +1655 -1521
  50. data/spec/isodoc/presentation_xml_spec.rb +345 -338
  51. data/spec/isodoc/ref_spec.rb +718 -723
  52. data/spec/isodoc/section_spec.rb +910 -902
  53. data/spec/isodoc/table_spec.rb +566 -556
  54. data/spec/isodoc/terms_spec.rb +252 -256
  55. data/spec/isodoc/xref_spec.rb +3040 -2985
  56. data/spec/isodoc/xslfo_convert_spec.rb +39 -0
  57. data/spec/spec_helper.rb +30 -29
  58. metadata +72 -69
  59. data/.rubocop.ribose.yml +0 -65
  60. data/.rubocop.tb.yml +0 -650
@@ -42,9 +42,7 @@ module IsoDoc
42
42
  end
43
43
 
44
44
  def xref_parse(node, out)
45
- target = /#/.match(node["target"]) ? node["target"].sub(/#/, ".pdf#") :
46
- "##{node["target"]}"
47
- out.a(**{ "href": target }) { |l| l << get_linkend(node) }
45
+ out.a(**{ "href": target_pdf(node) }) { |l| l << get_linkend(node) }
48
46
  end
49
47
  end
50
48
  end
@@ -1,14 +1,16 @@
1
+ require "base64"
2
+
1
3
  module IsoDoc
2
4
  class PresentationXMLConvert < ::IsoDoc::Convert
3
5
  def lower2cap(s)
4
- return s if /^[[:upper:]][[:upper:]]/.match(s)
6
+ return s if /^[[:upper:]][[:upper:]]/.match?(s)
7
+
5
8
  s.capitalize
6
9
  end
7
10
 
8
11
  def figure(docxml)
9
- docxml.xpath(ns("//figure")).each do |f|
10
- figure1(f)
11
- end
12
+ docxml.xpath(ns("//image")).each { |f| svg_extract(f) }
13
+ docxml.xpath(ns("//figure")).each { |f| figure1(f) }
12
14
  docxml.xpath(ns("//svgmap")).each do |s|
13
15
  if f = s.at(ns("./figure")) then s.replace(f)
14
16
  else
@@ -17,17 +19,27 @@ module IsoDoc
17
19
  end
18
20
  end
19
21
 
22
+ def svg_extract(f)
23
+ return unless %r{^data:image/svg\+xml;base64,}.match?(f["src"])
24
+
25
+ svg = Base64.strict_decode64(f["src"]
26
+ .sub(%r{^data:image/svg\+xml;base64,}, ""))
27
+ f.replace(svg.sub(/<\?xml[^>]*>/, ""))
28
+ end
29
+
20
30
  def figure1(f)
21
- return sourcecode1(f) if f["class"] == "pseudocode" ||
22
- f["type"] == "pseudocode"
31
+ return sourcecode1(f) if f["class"] == "pseudocode" || f["type"] == "pseudocode"
23
32
  return if labelled_ancestor(f) && f.ancestors("figure").empty?
24
33
  return if f.at(ns("./figure")) and !f.at(ns("./name"))
34
+
25
35
  lbl = @xrefs.anchor(f['id'], :label, false) or return
26
- prefix_name(f, "&nbsp;&mdash; ", l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
36
+ prefix_name(f, "&nbsp;&mdash; ",
37
+ l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
27
38
  end
28
39
 
29
40
  def prefix_name(f, delim, number, elem)
30
41
  return if number.nil? || number.empty?
42
+
31
43
  unless name = f.at(ns("./#{elem}"))
32
44
  f.children.empty? and f.add_child("<#{elem}></#{elem}>") or
33
45
  f.children.first.previous = "<#{elem}></#{elem}>"
@@ -46,6 +58,7 @@ module IsoDoc
46
58
  def sourcecode1(f)
47
59
  return if labelled_ancestor(f)
48
60
  return unless f.ancestors("example").empty?
61
+
49
62
  lbl = @xrefs.anchor(f['id'], :label, false) or return
50
63
  prefix_name(f, "&nbsp;&mdash; ", l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
51
64
  end
@@ -90,6 +103,7 @@ module IsoDoc
90
103
  # introduce name element
91
104
  def note1(f)
92
105
  return if f.parent.name == "bibitem"
106
+
93
107
  n = @xrefs.get[f["id"]]
94
108
  lbl = (@i18n.note if n.nil? || n[:label].nil? || n[:label].empty?) ?
95
109
  @i18n.note: l10n("#{@i18n.note} #{n[:label]}")
@@ -104,7 +118,7 @@ module IsoDoc
104
118
 
105
119
  # introduce name element
106
120
  def termnote1(f)
107
- lbl = l10n(@xrefs.anchor(f['id'], :label) || '???')
121
+ lbl = l10n(@xrefs.anchor(f["id"], :label) || "???")
108
122
  prefix_name(f, "", lower2cap(lbl), "name")
109
123
  end
110
124
 
@@ -128,7 +142,7 @@ module IsoDoc
128
142
 
129
143
  # introduce name element
130
144
  def recommendation1(f, type)
131
- n = @xrefs.anchor(f['id'], :label, false)
145
+ n = @xrefs.anchor(f["id"], :label, false)
132
146
  lbl = (n.nil? ? type : l10n("#{type} #{n}"))
133
147
  prefix_name(f, "", lbl, "name")
134
148
  end
@@ -142,7 +156,8 @@ module IsoDoc
142
156
  def table1(f)
143
157
  return if labelled_ancestor(f)
144
158
  return if f["unnumbered"] && !f.at(ns("./name"))
145
- n = @xrefs.anchor(f['id'], :label, false)
159
+
160
+ n = @xrefs.anchor(f["id"], :label, false)
146
161
  prefix_name(f, "&nbsp;&mdash; ", l10n("#{lower2cap @i18n.table} #{n}"), "name")
147
162
  end
148
163
 
@@ -154,7 +169,7 @@ module IsoDoc
154
169
  end
155
170
 
156
171
  def amend1(f)
157
- f.xpath(ns("./autonumber")).each { |a| a.remove }
172
+ f.xpath(ns("./autonumber")).each(&:remove)
158
173
  f.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
159
174
  f.xpath(ns("./description")).each { |a| a.replace(a.children) }
160
175
  f.replace(f.children)
@@ -1,4 +1,5 @@
1
1
  require "twitter_cldr"
2
+ require "bigdecimal"
2
3
 
3
4
  module IsoDoc
4
5
  class PresentationXMLConvert < ::IsoDoc::Convert
@@ -10,8 +11,7 @@ module IsoDoc
10
11
  if node["citeas"].nil? && node["bibitemid"]
11
12
  return @xrefs.anchor(node["bibitemid"] ,:xref) || "???"
12
13
  elsif node["target"] && node["droploc"]
13
- return @xrefs.anchor(node["target"], :value) ||
14
- @xrefs.anchor(node["target"], :label) ||
14
+ return @xrefs.anchor(node["target"], :value) || @xrefs.anchor(node["target"], :label) ||
15
15
  @xrefs.anchor(node["target"], :xref) || "???"
16
16
  elsif node["target"] && !/.#./.match(node["target"])
17
17
  linkend = anchor_linkend1(node)
@@ -22,9 +22,8 @@ module IsoDoc
22
22
  def anchor_linkend1(node)
23
23
  linkend = @xrefs.anchor(node["target"], :xref)
24
24
  container = @xrefs.anchor(node["target"], :container, false)
25
- (container && get_note_container_id(node) != container &&
26
- @xrefs.get[node["target"]]) &&
27
- linkend = prefix_container(container, linkend, node["target"])
25
+ (container && get_note_container_id(node) != container && @xrefs.get[node["target"]]) &&
26
+ linkend = prefix_container(container, linkend, node["target"])
28
27
  capitalise_xref(node, linkend)
29
28
  end
30
29
 
@@ -35,13 +34,11 @@ module IsoDoc
35
34
  return linkend if linkend[0,1].match(/\p{Upper}/)
36
35
  prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
37
36
  node.xpath("./preceding::text()")
38
- (prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map { |p| p.text }.join)) ?
39
- linkend&.capitalize : linkend
37
+ (prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map { |p| p.text }.join)) ? linkend&.capitalize : linkend
40
38
  end
41
39
 
42
40
  def nearest_block_parent(node)
43
- until %w(p title td th name formula
44
- li dt dd sourcecode pre).include?(node.name)
41
+ until %w(p title td th name formula li dt dd sourcecode pre).include?(node.name)
45
42
  node = node.parent
46
43
  end
47
44
  node
@@ -53,69 +50,79 @@ module IsoDoc
53
50
  end
54
51
  end
55
52
 
56
- def get_linkend(n)
57
- contents = non_locality_elems(n).select { |c| !c.text? || /\S/.match(c) }
53
+ def get_linkend(node)
54
+ contents = non_locality_elems(node).select { |c| !c.text? || /\S/.match(c) }
58
55
  return unless contents.empty?
59
- link = anchor_linkend(n, docid_l10n(n["target"] || n["citeas"]))
60
- link += eref_localities(n.xpath(ns("./locality | ./localityStack")), link)
61
- non_locality_elems(n).each { |n| n.remove }
62
- n.add_child(link)
56
+ link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
57
+ link += eref_localities(node.xpath(ns("./locality | ./localityStack")), link, node)
58
+ non_locality_elems(node).each { |n| n.remove }
59
+ node.add_child(link)
63
60
  end
64
61
  # so not <origin bibitemid="ISO7301" citeas="ISO 7301">
65
62
  # <locality type="section"><reference>3.1</reference></locality></origin>
66
63
 
67
- def eref_localities(refs, target)
64
+ def eref_localities(refs, target, n)
68
65
  ret = ""
69
66
  refs.each_with_index do |r, i|
70
67
  delim = ","
71
68
  delim = ";" if r.name == "localityStack" && i>0
72
- ret = eref_locality_stack(r, i, target, delim, ret)
69
+ ret = eref_locality_stack(r, i, target, delim, ret, n)
73
70
  end
74
71
  ret
75
72
  end
76
73
 
77
- def eref_locality_stack(r, i, target, delim, ret)
74
+ def eref_locality_stack(r, i, target, delim, ret, n)
78
75
  if r.name == "localityStack"
79
76
  r.elements.each_with_index do |rr, j|
80
- ret += eref_localities0(rr, j, target, delim)
77
+ ret += eref_localities0(rr, j, target, delim, n)
81
78
  delim = ","
82
79
  end
83
80
  else
84
- ret += eref_localities0(r, i, target, delim)
81
+ ret += eref_localities0(r, i, target, delim, n)
85
82
  end
86
83
  ret
87
84
  end
88
85
 
89
- def eref_localities0(r, i, target, delim)
86
+ def eref_localities0(r, i, target, delim, n)
90
87
  if r["type"] == "whole" then l10n("#{delim} #{@i18n.wholeoftext}")
91
88
  else
92
89
  eref_localities1(target, r["type"], r.at(ns("./referenceFrom")),
93
- r.at(ns("./referenceTo")), delim, @lang)
90
+ r.at(ns("./referenceTo")), delim, n, @lang)
94
91
  end
95
92
  end
96
93
 
97
94
  # TODO: move to localization file
98
- def eref_localities1_zh(target, type, from, to, delim)
95
+ def eref_localities1_zh(target, type, from, to, n, delim)
99
96
  ret = "#{delim} 第#{from.text}" if from
100
97
  ret += "&ndash;#{to.text}" if to
101
98
  loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize )
102
- ret += " #{loc}"
99
+ ret += " #{loc}" unless n["droploc"] == "true"
103
100
  ret
104
101
  end
105
102
 
106
103
  # TODO: move to localization file
107
- def eref_localities1(target, type, from, to, delim, lang = "en")
104
+ def eref_localities1(target, type, from, to, delim, n, lang = "en")
108
105
  return "" if type == "anchor"
109
- lang == "zh" and
110
- return l10n(eref_localities1_zh(target, type, from, to, delim))
106
+ lang == "zh" and return l10n(eref_localities1_zh(target, type, from, to, n, delim))
111
107
  ret = delim
112
- loc = @i18n.locality[type] || type.sub(/^locality:/, "").capitalize
113
- ret += " #{loc}"
108
+ ret += eref_locality_populate(type, n)
114
109
  ret += " #{from.text}" if from
115
110
  ret += "&ndash;#{to.text}" if to
116
111
  l10n(ret)
117
112
  end
118
113
 
114
+ def eref_locality_populate(type, n)
115
+ return "" if n["droploc"] == "true"
116
+ loc = @i18n.locality[type] || type.sub(/^locality:/, "")
117
+ loc = case n["case"]
118
+ when "capital" then loc.capitalize
119
+ when "lowercase" then loc.downcase
120
+ else
121
+ loc.capitalize
122
+ end
123
+ " #{loc}"
124
+ end
125
+
119
126
  def xref(docxml)
120
127
  docxml.xpath(ns("//xref")).each { |f| xref1(f) }
121
128
  end
@@ -163,23 +170,22 @@ module IsoDoc
163
170
  # TwitterCldr::DataReaders::NumberDataReader.new(locale).symbols
164
171
  def localize_maths(f, locale)
165
172
  f.xpath(".//m:mn", MATHML).each do |x|
166
- num = /\./.match(x.text) ? x.text.to_f : x.text.to_i
173
+ num = BigDecimal(x.text)
167
174
  precision = /\./.match(x.text) ? x.text.sub(/^.*\./, "").size : 0
168
175
  x.children = localized_number(num, locale, precision)
169
176
  end
170
177
  end
171
178
 
172
- # By itself twiiter cldr does not support fraction part digits grouping
179
+ # By itself twitter-cldr does not support fraction part digits grouping
173
180
  # and custom delimeter, will decorate fraction part manually
174
181
  def localized_number(num, locale, precision)
175
- localized = precision == 0 ? num.localize(locale).to_s :
182
+ localized = (precision == 0) ? num.localize(locale).to_s :
176
183
  num.localize(locale).to_decimal.to_s(:precision => precision)
177
184
  twitter_cldr_reader_symbols = twitter_cldr_reader(locale)
178
185
  return localized unless twitter_cldr_reader_symbols[:decimal]
179
186
  integer, fraction = localized.split(twitter_cldr_reader_symbols[:decimal])
180
187
  return localized if fraction.nil? || fraction.length.zero?
181
- [integer, decorate_fraction_part(fraction, locale)].
182
- join(twitter_cldr_reader_symbols[:decimal])
188
+ [integer, decorate_fraction_part(fraction, locale)].join(twitter_cldr_reader_symbols[:decimal])
183
189
  end
184
190
 
185
191
  def decorate_fraction_part(fract, locale)
@@ -229,8 +235,7 @@ module IsoDoc
229
235
  end
230
236
 
231
237
  def variant1(node)
232
- if (!node["lang"] || node["lang"] == @lang) &&
233
- (!node["script"] || node["script"] == @script)
238
+ if (!node["lang"] || node["lang"] == @lang) && (!node["script"] || node["script"] == @script)
234
239
  elsif found_matching_variant_sibling(node)
235
240
  node["remove"] = "true"
236
241
  else
@@ -238,13 +243,14 @@ module IsoDoc
238
243
  end
239
244
  end
240
245
 
246
+ private
247
+
241
248
  def found_matching_variant_sibling(node)
242
249
  prev = node.xpath("./preceding-sibling::xmlns:variant")
243
250
  foll = node.xpath("./following-sibling::xmlns:variant")
244
251
  found = false
245
252
  (prev + foll).each do |n|
246
- found = true if n["lang"] == @lang &&
247
- (!n["script"] || n["script"] == @script)
253
+ found = true if n["lang"] == @lang && (!n["script"] || n["script"] == @script)
248
254
  end
249
255
  found
250
256
  end
@@ -59,7 +59,7 @@ module IsoDoc
59
59
  variant docxml
60
60
  end
61
61
 
62
- def postprocess(result, filename, dir)
62
+ def postprocess(result, filename, _dir)
63
63
  toXML(result, filename)
64
64
  @files_to_delete.each { |f| FileUtils.rm_rf f }
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "1.5.2".freeze
2
+ VERSION = "1.6.1".freeze
3
3
  end
@@ -2,7 +2,7 @@ module IsoDoc::WordFunction
2
2
  module Footnotes
3
3
  def bookmarkid
4
4
  ret = "X"
5
- until !@bookmarks_allocated[ret] do
5
+ until !@bookmarks_allocated[ret]
6
6
  ret = Random.rand(1000000000)
7
7
  end
8
8
  @bookmarks_allocated[ret] = true
@@ -11,6 +11,7 @@ module IsoDoc::WordFunction
11
11
 
12
12
  def footnotes(div)
13
13
  return if @footnotes.empty?
14
+
14
15
  @footnotes.each { |fn| div.parent << fn }
15
16
  end
16
17
 
@@ -52,6 +53,7 @@ module IsoDoc::WordFunction
52
53
  def get_table_ancestor_id(node)
53
54
  table = node.ancestors("table") || node.ancestors("figure")
54
55
  return UUIDTools::UUID.random_create.to_s if table.empty?
56
+
55
57
  table.last["id"]
56
58
  end
57
59
 
@@ -61,30 +63,34 @@ module IsoDoc::WordFunction
61
63
  make_table_footnote_link(out, tid + fn, fn)
62
64
  # do not output footnote text if we have already seen it for this table
63
65
  return if @seen_footnote.include?(tid + fn)
66
+
64
67
  @in_footnote = true
65
68
  out.aside { |a| a << make_table_footnote_text(node, tid + fn, fn) }
66
69
  @in_footnote = false
67
70
  @seen_footnote << (tid + fn)
68
71
  end
69
72
 
70
- def seen_footnote_parse(node, out, fn)
71
- out.span **{style: "mso-element:field-begin"}
72
- out << " NOTEREF _Ref#{@fn_bookmarks[fn]} \\f \\h"
73
- out.span **{style: "mso-element:field-separator"}
74
- out.span **{class: "MsoFootnoteReference"} do |s|
75
- s << fn
73
+ def seen_footnote_parse(_node, out, footnote)
74
+ out.span **{ style: "mso-element:field-begin" }
75
+ out << " NOTEREF _Ref#{@fn_bookmarks[footnote]} \\f \\h"
76
+ out.span **{ style: "mso-element:field-separator" }
77
+ out.span **{ class: "MsoFootnoteReference" } do |s|
78
+ s << footnote
76
79
  end
77
- out.span **{style: "mso-element:field-end"}
80
+ out.span **{ style: "mso-element:field-end" }
78
81
  end
79
82
 
80
83
  def footnote_parse(node, out)
81
84
  return table_footnote_parse(node, out) if (@in_table || @in_figure) &&
82
- !node.ancestors.map {|m| m.name }.include?("name")
85
+ !node.ancestors.map { |m| m.name }.include?("name")
86
+
83
87
  fn = node["reference"] || UUIDTools::UUID.random_create.to_s
84
88
  return seen_footnote_parse(node, out, fn) if @seen_footnote.include?(fn)
89
+
85
90
  @fn_bookmarks[fn] = bookmarkid
86
- out.span **{style: "mso-bookmark:_Ref#{@fn_bookmarks[fn]}"} do |s|
87
- s.a **{ "class": "FootnoteRef", "epub:type": "footnote", href: "#ftn#{fn}" } do |a|
91
+ out.span **{ style: "mso-bookmark:_Ref#{@fn_bookmarks[fn]}" } do |s|
92
+ s.a **{ "class": "FootnoteRef", "epub:type": "footnote",
93
+ href: "#ftn#{fn}" } do |a|
88
94
  a.sup { |sup| sup << fn }
89
95
  end
90
96
  end
@@ -94,12 +100,13 @@ module IsoDoc::WordFunction
94
100
  @seen_footnote << fn
95
101
  end
96
102
 
97
- def make_footnote(node, fn)
98
- return if @seen_footnote.include?(fn)
103
+ def make_footnote(node, footnote)
104
+ return if @seen_footnote.include?(footnote)
105
+
99
106
  @in_footnote = true
100
- @footnotes << make_generic_footnote_text(node, fn)
107
+ @footnotes << make_generic_footnote_text(node, footnote)
101
108
  @in_footnote = false
102
- @seen_footnote << fn
109
+ @seen_footnote << footnote
103
110
  end
104
111
  end
105
112
  end
@@ -22,6 +22,12 @@ module IsoDoc::WordFunction
22
22
  end
23
23
  end
24
24
 
25
+ def svg_parse(node, out)
26
+ svg = Base64.strict_encode64(node.to_xml)
27
+ r = node.replace("<img src='data:image/svg+xml;base64,#{svg}' mimetype='image/svg+xml'/>").first
28
+ image_parse(r, out, nil)
29
+ end
30
+
25
31
  def imgsrc(node)
26
32
  ret = svg_to_emf(node) and return ret
27
33
  return node["src"] unless %r{^data:}.match node["src"]
@@ -37,17 +37,27 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
37
37
 
38
38
  def toWord(result, filename, dir, header)
39
39
  result = from_xhtml(word_cleanup(to_xhtml(result)))
40
- unless @landscapestyle.empty?
41
- @wordstylesheet&.open
42
- @wordstylesheet&.write(@landscapestyle)
43
- @wordstylesheet&.close
44
- end
40
+ @wordstylesheet = wordstylesheet_update
45
41
  Html2Doc.process(result, filename: filename, stylesheet: @wordstylesheet&.path,
46
42
  header_file: header&.path, dir: dir,
47
43
  asciimathdelims: [@openmathdelim, @closemathdelim],
48
44
  liststyles: { ul: @ulstyle, ol: @olstyle })
49
45
  header&.unlink
50
- @wordstylesheet&.unlink
46
+ @wordstylesheet&.unlink if @wordstylesheet&.is_a?(Tempfile)
47
+ end
48
+
49
+ def wordstylesheet_update()
50
+ return if @wordstylesheet.nil?
51
+ f = File.open(@wordstylesheet.path, "a")
52
+ @landscapestyle.empty? or f.write(@landscapestyle)
53
+ if @wordstylesheet_override && @wordstylesheet
54
+ f.write(@wordstylesheet_override.read)
55
+ @wordstylesheet_override.close
56
+ elsif @wordstylesheet_override && !@wordstylesheet
57
+ @wordstylesheet = @wordstylesheet_override
58
+ end
59
+ f.close
60
+ @wordstylesheet
51
61
  end
52
62
 
53
63
  def word_admonition_images(docxml)