isodoc 1.7.3 → 1.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/isodoc.gemspec +7 -4
- data/lib/isodoc/class_utils.rb +2 -2
- data/lib/isodoc/convert.rb +2 -0
- data/lib/isodoc/function/blocks_example_note.rb +85 -79
- data/lib/isodoc/function/cleanup.rb +181 -175
- data/lib/isodoc/function/inline.rb +110 -108
- data/lib/isodoc/function/inline_simple.rb +55 -55
- data/lib/isodoc/function/lists.rb +75 -71
- data/lib/isodoc/function/references.rb +165 -160
- data/lib/isodoc/function/section.rb +140 -190
- data/lib/isodoc/function/section_titles.rb +82 -0
- data/lib/isodoc/function/table.rb +90 -87
- data/lib/isodoc/function/terms.rb +58 -56
- data/lib/isodoc/function/to_word_html.rb +3 -1
- data/lib/isodoc/function/utils.rb +34 -14
- data/lib/isodoc/html_function/comments.rb +107 -111
- data/lib/isodoc/html_function/footnotes.rb +68 -67
- data/lib/isodoc/html_function/html.rb +113 -103
- data/lib/isodoc/html_function/mathvariant_to_plain.rb +5 -3
- data/lib/isodoc/presentation_function/block.rb +73 -78
- data/lib/isodoc/presentation_function/concept.rb +68 -0
- data/lib/isodoc/presentation_function/image.rb +112 -0
- data/lib/isodoc/presentation_function/inline.rb +6 -39
- data/lib/isodoc/presentation_function/math.rb +9 -0
- data/lib/isodoc/presentation_function/section.rb +12 -1
- data/lib/isodoc/presentation_xml_convert.rb +3 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +176 -174
- data/lib/isodoc/word_function/comments.rb +117 -112
- data/lib/isodoc/word_function/footnotes.rb +88 -86
- data/lib/isodoc/word_function/inline.rb +42 -67
- data/lib/isodoc/word_function/postprocess_cover.rb +121 -110
- data/lib/isodoc/xref/xref_gen.rb +153 -150
- data/lib/isodoc/xslfo_convert.rb +2 -2
- data/lib/isodoc.rb +1 -1
- data/spec/assets/odf.svg +1 -4
- data/spec/isodoc/blocks_spec.rb +187 -32
- data/spec/isodoc/inline_spec.rb +300 -116
- data/spec/isodoc/postproc_spec.rb +38 -0
- data/spec/isodoc/presentation_xml_spec.rb +144 -0
- data/spec/isodoc/section_spec.rb +764 -0
- data/spec/isodoc/terms_spec.rb +116 -0
- metadata +63 -18
@@ -1,231 +1,233 @@
|
|
1
1
|
require_relative "./table"
|
2
2
|
require_relative "./inline"
|
3
3
|
|
4
|
-
module IsoDoc
|
5
|
-
module
|
6
|
-
|
7
|
-
head
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
21
|
-
|
22
|
-
div1.p { |p| p << " " } # 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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
21
|
+
def make_body1(body, _docxml)
|
22
|
+
body.div **{ class: "WordSection1" } do |div1|
|
23
|
+
div1.p { |p| p << " " } # 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 << " " } # placeholder
|
38
|
+
end
|
39
|
+
section_break(body)
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
50
|
+
def insert_tab(out, count)
|
51
|
+
out.span **attr_code(style: "mso-tab-count:#{count}") do |span|
|
52
|
+
[1..count].each { span << "  " }
|
53
|
+
end
|
52
54
|
end
|
53
|
-
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
def para_parse(node, out)
|
65
|
+
out.p **attr_code(para_attrs(node)) do |p|
|
66
|
+
unless @termdomain.empty?
|
67
|
+
p << "<#{@termdomain}> "
|
68
|
+
@termdomain = ""
|
69
|
+
end
|
70
|
+
node.children.each { |n| parse(n, p) unless n.name == "note" }
|
68
71
|
end
|
69
|
-
node.
|
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
|
-
|
75
|
-
|
75
|
+
WORD_DT_ATTRS = { class: @note ? "Note" : nil, align: "left",
|
76
|
+
style: "margin-left:0pt;text-align:left;" }.freeze
|
76
77
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
104
|
-
|
104
|
+
def dl_parse_notes(node, out)
|
105
|
+
return if node.elements.reject { |n| dt_dd? n }.empty?
|
105
106
|
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
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
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
-
|
157
|
+
node.children.each { |n| parse(n, div) }
|
155
158
|
end
|
156
|
-
node.children.each { |n| parse(n, div) }
|
157
|
-
end
|
158
159
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
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
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
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
|
-
|
194
|
-
|
194
|
+
def formula_where(deflist, out)
|
195
|
+
return unless deflist
|
195
196
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
197
|
+
out.p { |p| p << @i18n.where }
|
198
|
+
parse(deflist, out)
|
199
|
+
out.parent.at("./table")["class"] = "formula_dl"
|
200
|
+
end
|
200
201
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
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
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
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">☐ </span>'
|
218
|
+
elsif node["checkedcheckbox"] == "true"
|
219
|
+
li << '<span class="zzMoveToFollowing">☑ </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
|
-
|
225
|
-
|
226
|
-
|
225
|
+
def suffix_url(url)
|
226
|
+
return url if %r{^https?://}.match?(url)
|
227
|
+
return url unless File.extname(url).empty?
|
227
228
|
|
228
|
-
|
229
|
+
url.sub(/#{File.extname(url)}$/, ".doc")
|
230
|
+
end
|
229
231
|
end
|
230
232
|
end
|
231
233
|
end
|