isodoc 1.7.3 → 1.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/isodoc.gemspec +7 -4
  3. data/lib/isodoc/class_utils.rb +2 -2
  4. data/lib/isodoc/convert.rb +2 -0
  5. data/lib/isodoc/function/blocks_example_note.rb +85 -79
  6. data/lib/isodoc/function/cleanup.rb +181 -175
  7. data/lib/isodoc/function/inline.rb +110 -108
  8. data/lib/isodoc/function/inline_simple.rb +55 -55
  9. data/lib/isodoc/function/lists.rb +75 -71
  10. data/lib/isodoc/function/references.rb +165 -160
  11. data/lib/isodoc/function/section.rb +140 -190
  12. data/lib/isodoc/function/section_titles.rb +82 -0
  13. data/lib/isodoc/function/table.rb +90 -87
  14. data/lib/isodoc/function/terms.rb +58 -56
  15. data/lib/isodoc/function/to_word_html.rb +3 -1
  16. data/lib/isodoc/function/utils.rb +34 -14
  17. data/lib/isodoc/html_function/comments.rb +107 -111
  18. data/lib/isodoc/html_function/footnotes.rb +68 -67
  19. data/lib/isodoc/html_function/html.rb +113 -103
  20. data/lib/isodoc/html_function/mathvariant_to_plain.rb +5 -3
  21. data/lib/isodoc/presentation_function/block.rb +73 -78
  22. data/lib/isodoc/presentation_function/concept.rb +68 -0
  23. data/lib/isodoc/presentation_function/image.rb +112 -0
  24. data/lib/isodoc/presentation_function/inline.rb +6 -39
  25. data/lib/isodoc/presentation_function/math.rb +9 -0
  26. data/lib/isodoc/presentation_function/section.rb +12 -1
  27. data/lib/isodoc/presentation_xml_convert.rb +3 -0
  28. data/lib/isodoc/version.rb +1 -1
  29. data/lib/isodoc/word_function/body.rb +176 -174
  30. data/lib/isodoc/word_function/comments.rb +117 -112
  31. data/lib/isodoc/word_function/footnotes.rb +88 -86
  32. data/lib/isodoc/word_function/inline.rb +42 -67
  33. data/lib/isodoc/word_function/postprocess_cover.rb +121 -110
  34. data/lib/isodoc/xref/xref_gen.rb +153 -150
  35. data/lib/isodoc/xslfo_convert.rb +2 -2
  36. data/lib/isodoc.rb +1 -1
  37. data/spec/assets/odf.svg +1 -4
  38. data/spec/isodoc/blocks_spec.rb +187 -32
  39. data/spec/isodoc/inline_spec.rb +300 -116
  40. data/spec/isodoc/postproc_spec.rb +38 -0
  41. data/spec/isodoc/presentation_xml_spec.rb +144 -0
  42. data/spec/isodoc/section_spec.rb +764 -0
  43. data/spec/isodoc/terms_spec.rb +116 -0
  44. metadata +63 -18
@@ -1,231 +1,233 @@
1
1
  require_relative "./table"
2
2
  require_relative "./inline"
3
3
 
4
- module IsoDoc::WordFunction
5
- module Body
6
- def define_head(head, filename, _dir)
7
- head.style do |style|
8
- loc = File.join(File.dirname(__FILE__), "..", "base_style",
9
- "metanorma_word.scss")
10
- stylesheet = File.read(loc, encoding: "utf-8")
11
- style.comment "\n#{stylesheet}\n"
12
- end
13
- super
14
- end
15
-
16
- def body_attr
17
- { lang: "EN-US", link: "blue", vlink: "#954F72" }
18
- end
4
+ module IsoDoc
5
+ module WordFunction
6
+ module Body
7
+ def define_head(head, filename, _dir)
8
+ head.style do |style|
9
+ loc = File.join(File.dirname(__FILE__), "..", "base_style",
10
+ "metanorma_word.scss")
11
+ stylesheet = File.read(loc, encoding: "utf-8")
12
+ style.comment "\n#{stylesheet}\n"
13
+ end
14
+ super
15
+ end
19
16
 
20
- def make_body1(body, _docxml)
21
- body.div **{ class: "WordSection1" } do |div1|
22
- div1.p { |p| p << "&nbsp;" } # placeholder
17
+ def body_attr
18
+ { lang: "EN-US", link: "blue", vlink: "#954F72" }
23
19
  end
24
- section_break(body)
25
- end
26
20
 
27
- def make_body2(body, docxml)
28
- body.div **{ class: "WordSection2" } do |div2|
29
- boilerplate docxml, div2
30
- preface_block docxml, div2
31
- abstract docxml, div2
32
- foreword docxml, div2
33
- introduction docxml, div2
34
- preface docxml, div2
35
- acknowledgements docxml, div2
36
- div2.p { |p| p << "&nbsp;" } # placeholder
37
- end
38
- section_break(body)
39
- end
21
+ def make_body1(body, _docxml)
22
+ body.div **{ class: "WordSection1" } do |div1|
23
+ div1.p { |p| p << "&nbsp;" } # placeholder
24
+ end
25
+ section_break(body)
26
+ end
27
+
28
+ def make_body2(body, docxml)
29
+ body.div **{ class: "WordSection2" } do |div2|
30
+ boilerplate docxml, div2
31
+ preface_block docxml, div2
32
+ abstract docxml, div2
33
+ foreword docxml, div2
34
+ introduction docxml, div2
35
+ preface docxml, div2
36
+ acknowledgements docxml, div2
37
+ div2.p { |p| p << "&nbsp;" } # placeholder
38
+ end
39
+ section_break(body)
40
+ end
40
41
 
41
- def make_body3(body, docxml)
42
- body.div **{ class: "WordSection3" } do |div3|
43
- middle docxml, div3
44
- footnotes div3
45
- comments div3
42
+ def make_body3(body, docxml)
43
+ body.div **{ class: "WordSection3" } do |div3|
44
+ middle docxml, div3
45
+ footnotes div3
46
+ comments div3
47
+ end
46
48
  end
47
- end
48
49
 
49
- def insert_tab(out, n)
50
- out.span **attr_code(style: "mso-tab-count:#{n}") do |span|
51
- [1..n].each { span << "&#xA0; " }
50
+ def insert_tab(out, count)
51
+ out.span **attr_code(style: "mso-tab-count:#{count}") do |span|
52
+ [1..count].each { span << "&#xA0; " }
53
+ end
52
54
  end
53
- end
54
55
 
55
- def para_class(_node)
56
- classtype = nil
57
- classtype = "Note" if @note
58
- classtype = "MsoCommentText" if in_comment
59
- classtype = "Sourcecode" if @annotation
60
- classtype
61
- end
56
+ def para_class(_node)
57
+ classtype = nil
58
+ classtype = "Note" if @note
59
+ classtype = "MsoCommentText" if in_comment
60
+ classtype = "Sourcecode" if @annotation
61
+ classtype
62
+ end
62
63
 
63
- def para_parse(node, out)
64
- out.p **attr_code(para_attrs(node)) do |p|
65
- unless @termdomain.empty?
66
- p << "&lt;#{@termdomain}&gt; "
67
- @termdomain = ""
64
+ def para_parse(node, out)
65
+ out.p **attr_code(para_attrs(node)) do |p|
66
+ unless @termdomain.empty?
67
+ p << "&lt;#{@termdomain}&gt; "
68
+ @termdomain = ""
69
+ end
70
+ node.children.each { |n| parse(n, p) unless n.name == "note" }
68
71
  end
69
- node.children.each { |n| parse(n, p) unless n.name == "note" }
72
+ node.xpath(ns("./note")).each { |n| parse(n, out) }
70
73
  end
71
- node.xpath(ns("./note")).each { |n| parse(n, out) }
72
- end
73
74
 
74
- WORD_DT_ATTRS = { class: @note ? "Note" : nil, align: "left",
75
- style: "margin-left:0pt;text-align:left;" }.freeze
75
+ WORD_DT_ATTRS = { class: @note ? "Note" : nil, align: "left",
76
+ style: "margin-left:0pt;text-align:left;" }.freeze
76
77
 
77
- def dt_parse(dt, term)
78
- term.p **attr_code(WORD_DT_ATTRS) do |p|
79
- if dt.elements.empty?
80
- p << dt.text
81
- else
82
- dt.children.each { |n| parse(n, p) }
78
+ def dt_parse(dterm, term)
79
+ term.p **attr_code(WORD_DT_ATTRS) do |p|
80
+ if dterm.elements.empty?
81
+ p << dterm.text
82
+ else
83
+ dterm.children.each { |n| parse(n, p) }
84
+ end
83
85
  end
84
86
  end
85
- end
86
87
 
87
- def dl_parse(node, out)
88
- out.table **{ class: "dl" } do |v|
89
- node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
90
- v.tr do |tr|
91
- tr.td **{ valign: "top", align: "left" } do |term|
92
- dt_parse(dt, term)
93
- end
94
- tr.td **{ valign: "top" } do |listitem|
95
- dd.children.each { |n| parse(n, listitem) }
88
+ def dl_parse(node, out)
89
+ out.table **{ class: "dl" } do |v|
90
+ node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
91
+ v.tr do |tr|
92
+ tr.td **{ valign: "top", align: "left" } do |term|
93
+ dt_parse(dt, term)
94
+ end
95
+ tr.td **{ valign: "top" } do |listitem|
96
+ dd.children.each { |n| parse(n, listitem) }
97
+ end
96
98
  end
97
99
  end
100
+ dl_parse_notes(node, v)
98
101
  end
99
- dl_parse_notes(node, v)
100
102
  end
101
- end
102
103
 
103
- def dl_parse_notes(node, v)
104
- return if node.elements.reject { |n| dt_dd? n }.empty?
104
+ def dl_parse_notes(node, out)
105
+ return if node.elements.reject { |n| dt_dd? n }.empty?
105
106
 
106
- v.tr do |tr|
107
- tr.td **{ colspan: 2 } do |td|
108
- node.elements.reject { |n| dt_dd? n }.each { |n| parse(n, td) }
107
+ out.tr do |tr|
108
+ tr.td **{ colspan: 2 } do |td|
109
+ node.elements.reject { |n| dt_dd? n }.each { |n| parse(n, td) }
110
+ end
109
111
  end
110
112
  end
111
- end
112
113
 
113
- def figure_get_or_make_dl(node)
114
- dl = node.at(".//table[@class = 'dl']")
115
- if dl.nil?
116
- node.add_child("<p><b>#{@i18n.key}</b></p><table class='dl'></table>")
114
+ def figure_get_or_make_dl(node)
117
115
  dl = node.at(".//table[@class = 'dl']")
116
+ if dl.nil?
117
+ node.add_child("<p><b>#{@i18n.key}</b></p><table class='dl'></table>")
118
+ dl = node.at(".//table[@class = 'dl']")
119
+ end
120
+ dl
121
+ end
122
+
123
+ def figure_aside_process(fig, aside, key)
124
+ # get rid of footnote link, it is in diagram
125
+ fig&.at("./a[@class='TableFootnoteRef']")&.remove
126
+ fnref = fig.at(".//span[@class='TableFootnoteRef']/..")
127
+ tr = key.add_child("<tr></tr>").first
128
+ dt = tr.add_child("<td valign='top' align='left'></td>").first
129
+ dd = tr.add_child("<td valign='top'></td>").first
130
+ fnref.parent = dt
131
+ aside.xpath(".//p").each do |a|
132
+ a.delete("class")
133
+ a.parent = dd
134
+ end
118
135
  end
119
- dl
120
- end
121
-
122
- def figure_aside_process(fig, aside, key)
123
- # get rid of footnote link, it is in diagram
124
- fig&.at("./a[@class='TableFootnoteRef']")&.remove
125
- fnref = fig.at(".//span[@class='TableFootnoteRef']/..")
126
- tr = key.add_child("<tr></tr>").first
127
- dt = tr.add_child("<td valign='top' align='left'></td>").first
128
- dd = tr.add_child("<td valign='top'></td>").first
129
- fnref.parent = dt
130
- aside.xpath(".//p").each do |a|
131
- a.delete("class")
132
- a.parent = dd
133
- end
134
- end
135
136
 
136
- def note_p_parse(node, div)
137
- name = node&.at(ns("./name"))&.remove
138
- div.p **{ class: "Note" } do |p|
139
- p.span **{ class: "note_label" } do |s|
140
- name and name.children.each { |n| parse(n, s) }
137
+ def note_p_parse(node, div)
138
+ name = node&.at(ns("./name"))&.remove
139
+ div.p **{ class: "Note" } do |p|
140
+ p.span **{ class: "note_label" } do |s|
141
+ name&.children&.each { |n| parse(n, s) }
142
+ end
143
+ insert_tab(p, 1)
144
+ node.first_element_child.children.each { |n| parse(n, p) }
141
145
  end
142
- insert_tab(p, 1)
143
- node.first_element_child.children.each { |n| parse(n, p) }
146
+ node.element_children[1..-1].each { |n| parse(n, div) }
144
147
  end
145
- node.element_children[1..-1].each { |n| parse(n, div) }
146
- end
147
148
 
148
- def note_parse1(node, div)
149
- name = node&.at(ns("./name"))&.remove
150
- div.p **{ class: "Note" } do |p|
151
- p.span **{ class: "note_label" } do |s|
152
- name and name.children.each { |n| parse(n, s) }
149
+ def note_parse1(node, div)
150
+ name = node&.at(ns("./name"))&.remove
151
+ div.p **{ class: "Note" } do |p|
152
+ p.span **{ class: "note_label" } do |s|
153
+ name&.children&.each { |n| parse(n, s) }
154
+ end
155
+ insert_tab(p, 1)
153
156
  end
154
- insert_tab(p, 1)
157
+ node.children.each { |n| parse(n, div) }
155
158
  end
156
- node.children.each { |n| parse(n, div) }
157
- end
158
159
 
159
- def termnote_parse(node, out)
160
- name = node&.at(ns("./name"))&.remove
161
- out.div **note_attrs(node) do |div|
162
- div.p **{ class: "Note" } do |p|
163
- if name
164
- name.children.each { |n| parse(n, p) }
165
- p << l10n(": ")
160
+ def termnote_parse(node, out)
161
+ name = node&.at(ns("./name"))&.remove
162
+ out.div **note_attrs(node) do |div|
163
+ div.p **{ class: "Note" } do |p|
164
+ if name
165
+ name.children.each { |n| parse(n, p) }
166
+ p << l10n(": ")
167
+ end
168
+ para_then_remainder(node.first_element_child, node, p, div)
166
169
  end
167
- para_then_remainder(node.first_element_child, node, p, div)
168
170
  end
169
171
  end
170
- end
171
172
 
172
- def para_attrs(node)
173
- attrs = { class: para_class(node), id: node["id"], style: "" }
174
- unless node["align"].nil?
175
- attrs[:align] = node["align"] unless node["align"] == "justify"
176
- attrs[:style] += "text-align:#{node['align']};"
173
+ def para_attrs(node)
174
+ attrs = { class: para_class(node), id: node["id"], style: "" }
175
+ unless node["align"].nil?
176
+ attrs[:align] = node["align"] unless node["align"] == "justify"
177
+ attrs[:style] += "text-align:#{node['align']};"
178
+ end
179
+ attrs[:style] += keep_style(node).to_s
180
+ attrs[:style] = nil if attrs[:style].empty?
181
+ attrs
177
182
  end
178
- attrs[:style] += keep_style(node).to_s
179
- attrs[:style] = nil if attrs[:style].empty?
180
- attrs
181
- end
182
183
 
183
- def example_table_attr(node)
184
- super.merge({
185
- style: "mso-table-lspace:15.0cm;margin-left:423.0pt;"\
186
- "mso-table-rspace:15.0cm;margin-right:423.0pt;"\
187
- "mso-table-anchor-horizontal:column;"\
188
- "mso-table-overlap:never;border-collapse:collapse;"\
189
- "#{keep_style(node)}",
190
- })
191
- end
184
+ def example_table_attr(node)
185
+ super.merge(
186
+ style: "mso-table-lspace:15.0cm;margin-left:423.0pt;"\
187
+ "mso-table-rspace:15.0cm;margin-right:423.0pt;"\
188
+ "mso-table-anchor-horizontal:column;"\
189
+ "mso-table-overlap:never;border-collapse:collapse;"\
190
+ "#{keep_style(node)}",
191
+ )
192
+ end
192
193
 
193
- def formula_where(deflist, out)
194
- return unless deflist
194
+ def formula_where(deflist, out)
195
+ return unless deflist
195
196
 
196
- out.p { |p| p << @i18n.where }
197
- parse(deflist, out)
198
- out.parent.at("./table")["class"] = "formula_dl"
199
- end
197
+ out.p { |p| p << @i18n.where }
198
+ parse(deflist, out)
199
+ out.parent.at("./table")["class"] = "formula_dl"
200
+ end
200
201
 
201
- def formula_parse1(node, out)
202
- out.div **attr_code(class: "formula") do |div|
203
- div.p do |_p|
204
- parse(node.at(ns("./stem")), div)
205
- insert_tab(div, 1)
206
- if lbl = node&.at(ns("./name"))&.text
207
- div << "(#{lbl})"
202
+ def formula_parse1(node, out)
203
+ out.div **attr_code(class: "formula") do |div|
204
+ div.p do |_p|
205
+ parse(node.at(ns("./stem")), div)
206
+ insert_tab(div, 1)
207
+ if lbl = node&.at(ns("./name"))&.text
208
+ div << "(#{lbl})"
209
+ end
208
210
  end
209
211
  end
210
212
  end
211
- end
212
213
 
213
- def li_parse(node, out)
214
- out.li **attr_code(id: node["id"]) do |li|
215
- if node["uncheckedcheckbox"] == "true"
216
- li << '<span class="zzMoveToFollowing">&#x2610; </span>'
217
- elsif node["checkedcheckbox"] == "true"
218
- li << '<span class="zzMoveToFollowing">&#x2611; </span>'
214
+ def li_parse(node, out)
215
+ out.li **attr_code(id: node["id"]) do |li|
216
+ if node["uncheckedcheckbox"] == "true"
217
+ li << '<span class="zzMoveToFollowing">&#x2610; </span>'
218
+ elsif node["checkedcheckbox"] == "true"
219
+ li << '<span class="zzMoveToFollowing">&#x2611; </span>'
220
+ end
221
+ node.children.each { |n| parse(n, li) }
219
222
  end
220
- node.children.each { |n| parse(n, li) }
221
223
  end
222
- end
223
224
 
224
- def suffix_url(url)
225
- return url if %r{^https?://}.match?(url)
226
- return url unless File.extname(url).empty?
225
+ def suffix_url(url)
226
+ return url if %r{^https?://}.match?(url)
227
+ return url unless File.extname(url).empty?
227
228
 
228
- url.sub(/#{File.extname(url)}$/, ".doc")
229
+ url.sub(/#{File.extname(url)}$/, ".doc")
230
+ end
229
231
  end
230
232
  end
231
233
  end