isodoc 1.2.0 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/isodoc-yaml/i18n-fr.yaml +1 -1
- data/lib/isodoc/base_style/metanorma_word.css +6 -0
- data/lib/isodoc/base_style/metanorma_word.scss +6 -0
- data/lib/isodoc/convert.rb +1 -1
- data/lib/isodoc/function/blocks.rb +1 -0
- data/lib/isodoc/function/cleanup.rb +1 -1
- data/lib/isodoc/function/references.rb +4 -2
- data/lib/isodoc/function/section.rb +13 -1
- data/lib/isodoc/function/table.rb +1 -0
- data/lib/isodoc/function/to_word_html.rb +2 -0
- data/lib/isodoc/function/utils.rb +2 -2
- data/lib/isodoc/html_function/html.rb +1 -0
- data/lib/isodoc/i18n.rb +0 -1
- data/lib/isodoc/metadata.rb +10 -4
- data/lib/isodoc/presentation_function/bibdata.rb +24 -0
- data/lib/isodoc/presentation_function/block.rb +14 -0
- data/lib/isodoc/presentation_function/inline.rb +27 -14
- data/lib/isodoc/presentation_xml_convert.rb +4 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +1 -0
- data/lib/isodoc/word_function/postprocess.rb +1 -1
- data/lib/isodoc/word_function/table.rb +3 -2
- data/lib/isodoc/xref.rb +1 -0
- data/lib/isodoc/xref/xref_anchor.rb +8 -3
- data/lib/isodoc/xref/xref_counter.rb +21 -7
- data/lib/isodoc/xref/xref_gen.rb +29 -6
- data/lib/isodoc/xref/xref_sect_gen.rb +1 -1
- data/spec/assets/i18n.yaml +9 -0
- data/spec/isodoc/blocks_spec.rb +281 -13
- data/spec/isodoc/cleanup_spec.rb +3 -1
- data/spec/isodoc/i18n_spec.rb +43 -5
- data/spec/isodoc/inline_spec.rb +47 -5
- data/spec/isodoc/metadata_spec.rb +3 -1
- data/spec/isodoc/postproc_spec.rb +39 -3
- data/spec/isodoc/ref_spec.rb +4 -1
- data/spec/isodoc/section_spec.rb +134 -10
- data/spec/isodoc/table_spec.rb +306 -207
- data/spec/isodoc/terms_spec.rb +1 -1
- data/spec/isodoc/xref_spec.rb +46 -18
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f76ecc765fd3176ab1e46bd2b91b2a1d5746554772047b7137581ecc54a1ab9
|
4
|
+
data.tar.gz: b98fe5eee6522b4d5992c4213f3180e1c95f92f358b0c56ff3a2b5f66973a900
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a2649fdf7365e2554c0e0bdec19aa0cf6e50fad624d4252dd99aa88d436b95b1ff24e823c6a0a9be4afa7e875921b11310e67595b308a9c81c8758b6e8cf302
|
7
|
+
data.tar.gz: d21cdae8851e757e999a54809868e15a8004fcc387afa78e79e60a4605df07108c454fc3c04e0a3e79f3a5c14af9ca8cdbbb855eca9fa47e254e3ff4a40d3ac4
|
@@ -16,6 +16,12 @@ td {
|
|
16
16
|
tr {
|
17
17
|
page-break-after: avoid; }
|
18
18
|
|
19
|
+
table.MsoISOTableBig tr {
|
20
|
+
page-break-inside: auto; }
|
21
|
+
|
22
|
+
table.MsoISOTableBig td {
|
23
|
+
page-break-inside: auto; }
|
24
|
+
|
19
25
|
span.stem {
|
20
26
|
font-family: "Cambria Math",serif;
|
21
27
|
mso-ascii-font-family: "Cambria Math";
|
@@ -13,6 +13,12 @@ table.MsoISOTable tr
|
|
13
13
|
td { page-break-inside:avoid; }
|
14
14
|
tr { page-break-after:avoid; }
|
15
15
|
|
16
|
+
table.MsoISOTableBig tr
|
17
|
+
{page-break-inside:auto;}
|
18
|
+
|
19
|
+
table.MsoISOTableBig td
|
20
|
+
{page-break-inside:auto;}
|
21
|
+
|
16
22
|
span.stem
|
17
23
|
{font-family:"Cambria Math",serif;
|
18
24
|
mso-ascii-font-family:"Cambria Math";
|
data/lib/isodoc/convert.rb
CHANGED
@@ -181,6 +181,7 @@ module IsoDoc::Function
|
|
181
181
|
def quote_attribution(node, out)
|
182
182
|
author = node.at(ns("./author"))
|
183
183
|
source = node.at(ns("./source"))
|
184
|
+
return if author.nil? && source.nil?
|
184
185
|
out.p **{ class: "QuoteAttribution" } do |p|
|
185
186
|
p << "— #{author.text}" if author
|
186
187
|
p << ", " if author && source
|
@@ -6,9 +6,9 @@ module IsoDoc::Function
|
|
6
6
|
|
7
7
|
def termref_cleanup(docxml)
|
8
8
|
docxml.
|
9
|
+
gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/, l10n(", #{@i18n.modified} [/TERMREF]")).
|
9
10
|
gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, "; ").
|
10
11
|
gsub(/\[TERMREF\]\s*/, l10n("[#{@i18n.source}: ")).
|
11
|
-
gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/, l10n(", #{@i18n.modified} [/TERMREF]")).
|
12
12
|
gsub(%r{\s*\[\/TERMREF\]\s*}, l10n("]")).
|
13
13
|
gsub(/\s*\[MODIFICATION\]/, l10n(", #{@i18n.modified} — "))
|
14
14
|
end
|
@@ -54,7 +54,8 @@ module IsoDoc::Function
|
|
54
54
|
def bibitem_ref_code(b)
|
55
55
|
id = b.at(ns("./docidentifier[@type = 'metanorma']"))
|
56
56
|
id1 = pref_ref_code(b)
|
57
|
-
id2 = b.at(ns("./docidentifier[@type = 'DOI' or @type = 'ISSN' or
|
57
|
+
id2 = b.at(ns("./docidentifier[@type = 'DOI' or @type = 'ISSN' or "\
|
58
|
+
"@type = 'ISBN']"))
|
58
59
|
return [id, id1, id2] if id || id1 || id2
|
59
60
|
id = Nokogiri::XML::Node.new("docidentifier", b.document)
|
60
61
|
id << "(NO ID)"
|
@@ -193,7 +194,8 @@ module IsoDoc::Function
|
|
193
194
|
def bibliography_parse(node, out)
|
194
195
|
title = node&.at(ns("./title"))&.text || ""
|
195
196
|
out.div do |div|
|
196
|
-
clause_parse_title(node, div, node.at(ns("./title")), out,
|
197
|
+
clause_parse_title(node, div, node.at(ns("./title")), out,
|
198
|
+
{ class: "Section3" })
|
197
199
|
biblio_list(node, div, true)
|
198
200
|
end
|
199
201
|
end
|
@@ -182,7 +182,6 @@ module IsoDoc::Function
|
|
182
182
|
page_break(out)
|
183
183
|
out.div **attr_code(id: f["id"]) do |s|
|
184
184
|
clause_name(nil, f.at(ns("./title")), s, { class: "AbstractTitle" })
|
185
|
-
#s.h1(**{ class: "AbstractTitle" }) { |h1| h1 << @i18n.abstract }
|
186
185
|
f.elements.each { |e| parse(e, s) unless e.name == "title" }
|
187
186
|
end
|
188
187
|
end
|
@@ -201,6 +200,19 @@ module IsoDoc::Function
|
|
201
200
|
end
|
202
201
|
end
|
203
202
|
|
203
|
+
def is_clause?(name)
|
204
|
+
%w(clause references definitions terms foreword introduction abstract
|
205
|
+
acknowledgements).include? name
|
206
|
+
end
|
207
|
+
|
208
|
+
def preface_block(isoxml, out)
|
209
|
+
p = isoxml.at(ns("//preface")) or return
|
210
|
+
p.elements.each do |e|
|
211
|
+
next if is_clause?(e.name)
|
212
|
+
parse(e, out)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
204
216
|
def copyright_parse(node, out)
|
205
217
|
out.div **{class: "boilerplate-copyright"} do |div|
|
206
218
|
node.children.each { |n| parse(n, div) }
|
@@ -82,6 +82,7 @@ module IsoDoc::Function
|
|
82
82
|
def make_tr_attr(td, row, totalrows, header)
|
83
83
|
style = td.name == "th" ? "font-weight:bold;" : ""
|
84
84
|
td["align"] and style += "text-align:#{td['align']};"
|
85
|
+
td["valign"] and style += "vertical-align:#{td['valign']};"
|
85
86
|
rowmax = td["rowspan"] ? row + td["rowspan"].to_i - 1 : row
|
86
87
|
style += <<~STYLE
|
87
88
|
border-top:#{row.zero? ? "#{SW} 1.5pt;" : 'none;'}
|
@@ -80,6 +80,7 @@ module IsoDoc::Function
|
|
80
80
|
def make_body3(body, docxml)
|
81
81
|
body.div **{ class: "main-section" } do |div3|
|
82
82
|
boilerplate docxml, div3
|
83
|
+
preface_block docxml, div3
|
83
84
|
abstract docxml, div3
|
84
85
|
foreword docxml, div3
|
85
86
|
introduction docxml, div3
|
@@ -220,6 +221,7 @@ module IsoDoc::Function
|
|
220
221
|
when "feedback-statement" then feedback_parse(node, out)
|
221
222
|
when "passthrough" then passthrough_parse(node, out)
|
222
223
|
when "variant" then variant_parse(node, out)
|
224
|
+
when "amend" then amend_parse(node, out)
|
223
225
|
when "tab" then clausedelimspace(out) # in Presentation XML only
|
224
226
|
else
|
225
227
|
error_parse(node, out)
|
@@ -154,7 +154,7 @@ module IsoDoc::Function
|
|
154
154
|
.get
|
155
155
|
.merge(@labels || {})
|
156
156
|
.merge(@meta.labels || {})
|
157
|
-
.merge(
|
157
|
+
.merge(fonts_options || {})
|
158
158
|
template = liquid(docxml)
|
159
159
|
template.render(meta.map { |k, v| [k.to_s, empty2nil(v)] }.to_h)
|
160
160
|
.gsub('<', '<').gsub('>', '>').gsub('&', '&')
|
@@ -184,7 +184,7 @@ module IsoDoc::Function
|
|
184
184
|
|
185
185
|
def labelled_ancestor(node)
|
186
186
|
!node.ancestors('example, requirement, recommendation, permission, '\
|
187
|
-
'table, figure, sourcecode').empty?
|
187
|
+
'note, table, figure, sourcecode').empty?
|
188
188
|
end
|
189
189
|
end
|
190
190
|
end
|
data/lib/isodoc/i18n.rb
CHANGED
data/lib/isodoc/metadata.rb
CHANGED
@@ -98,8 +98,9 @@ module IsoDoc
|
|
98
98
|
|
99
99
|
def doctype(isoxml, _out)
|
100
100
|
b = isoxml&.at(ns('//bibdata/ext/doctype'))&.text || return
|
101
|
-
|
102
|
-
|
101
|
+
set(:doctype, status_print(b))
|
102
|
+
b = isoxml&.at(ns('//local_bibdata/ext/doctype'))&.text || return
|
103
|
+
set(:doctype_display, status_print(b))
|
103
104
|
end
|
104
105
|
|
105
106
|
def iso?(org)
|
@@ -135,9 +136,14 @@ module IsoDoc
|
|
135
136
|
docstatus = isoxml.at(ns('//bibdata/status/stage'))
|
136
137
|
set(:unpublished, true)
|
137
138
|
if docstatus
|
139
|
+
docstatus_local = isoxml.at(ns('//local_bibdata/status/stage'))
|
138
140
|
set(:stage, status_print(docstatus.text))
|
141
|
+
docstatus_local and
|
142
|
+
set(:stage_display, status_print(docstatus_local.text))
|
139
143
|
(i = isoxml&.at(ns('//bibdata/status/substage'))&.text) &&
|
140
144
|
set(:substage, i)
|
145
|
+
(i = isoxml&.at(ns('//local_bibdata/status/substage'))&.text) &&
|
146
|
+
set(:substage_display, i)
|
141
147
|
(i = isoxml&.at(ns('//bibdata/status/iteration'))&.text) &&
|
142
148
|
set(:iteration, i)
|
143
149
|
set(:unpublished, unpublished(docstatus.text))
|
@@ -148,7 +154,7 @@ module IsoDoc
|
|
148
154
|
|
149
155
|
def stage_abbr(docstatus)
|
150
156
|
status_print(docstatus).split(/ /)
|
151
|
-
|
157
|
+
.map { |s| s[0].upcase }.join('')
|
152
158
|
end
|
153
159
|
|
154
160
|
def unpublished(status)
|
@@ -156,7 +162,7 @@ module IsoDoc
|
|
156
162
|
end
|
157
163
|
|
158
164
|
def status_print(status)
|
159
|
-
status.split(
|
165
|
+
status.split(/[- ]/).map(&:capitalize).join(' ')
|
160
166
|
end
|
161
167
|
|
162
168
|
def docid(isoxml, _out)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
class PresentationXMLConvert < ::IsoDoc::Convert
|
3
|
+
def bibdata(docxml)
|
4
|
+
a = docxml.at(ns("//bibdata")) or return
|
5
|
+
b = a.dup
|
6
|
+
b.name = "local_bibdata"
|
7
|
+
bibdata_i18n(b)
|
8
|
+
a.next = b
|
9
|
+
end
|
10
|
+
|
11
|
+
def bibdata_i18n(b)
|
12
|
+
hash_translate(b, @i18n.get["doctype_dict"], "./ext/doctype")
|
13
|
+
hash_translate(b, @i18n.get["stage_dict"], "./status/stage")
|
14
|
+
hash_translate(b, @i18n.get["substage_dict"], "./status/substage")
|
15
|
+
end
|
16
|
+
|
17
|
+
def hash_translate(bibdata, hash, xpath)
|
18
|
+
hash.is_a? Hash or return
|
19
|
+
x = bibdata.at(ns(xpath)) or return
|
20
|
+
hash[x.text] or return
|
21
|
+
x.children = hash[x.text]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -134,5 +134,19 @@ module IsoDoc
|
|
134
134
|
n = @xrefs.anchor(f['id'], :label, false)
|
135
135
|
prefix_name(f, " — ", l10n("#{@i18n.table} #{n}"), "name")
|
136
136
|
end
|
137
|
+
|
138
|
+
# we use this to eliminate the semantic amend blocks from rendering
|
139
|
+
def amend(docxml)
|
140
|
+
docxml.xpath(ns("//amend")).each do |f|
|
141
|
+
amend1(f)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def amend1(f)
|
146
|
+
f.xpath(ns("./autonumber")).each { |a| a.remove }
|
147
|
+
f.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
|
148
|
+
f.xpath(ns("./description")).each { |a| a.replace(a.children) }
|
149
|
+
f.replace(f.children)
|
150
|
+
end
|
137
151
|
end
|
138
152
|
end
|
@@ -7,17 +7,25 @@ module IsoDoc
|
|
7
7
|
def anchor_linkend(node, linkend)
|
8
8
|
if node["citeas"].nil? && node["bibitemid"]
|
9
9
|
return @xrefs.anchor(node["bibitemid"] ,:xref) || "???"
|
10
|
+
elsif node["target"] && node["droploc"]
|
11
|
+
return @xrefs.anchor(node["target"], :value) ||
|
12
|
+
@xrefs.anchor(node["target"], :label) ||
|
13
|
+
@xrefs.anchor(node["target"], :xref) || "???"
|
10
14
|
elsif node["target"] && !/.#./.match(node["target"])
|
11
|
-
linkend =
|
12
|
-
container = @xrefs.anchor(node["target"], :container, false)
|
13
|
-
(container && get_note_container_id(node) != container &&
|
14
|
-
@xrefs.get[node["target"]]) &&
|
15
|
-
linkend = prefix_container(container, linkend, node["target"])
|
16
|
-
linkend = capitalise_xref(node, linkend)
|
15
|
+
linkend = anchor_linkend1(node)
|
17
16
|
end
|
18
17
|
linkend || "???"
|
19
18
|
end
|
20
19
|
|
20
|
+
def anchor_linkend1(node)
|
21
|
+
linkend = @xrefs.anchor(node["target"], :xref)
|
22
|
+
container = @xrefs.anchor(node["target"], :container, false)
|
23
|
+
(container && get_note_container_id(node) != container &&
|
24
|
+
@xrefs.get[node["target"]]) &&
|
25
|
+
linkend = prefix_container(container, linkend, node["target"])
|
26
|
+
capitalise_xref(node, linkend)
|
27
|
+
end
|
28
|
+
|
21
29
|
def capitalise_xref(node, linkend)
|
22
30
|
return linkend unless %w(Latn Cyrl Grek).include? @script
|
23
31
|
return linkend&.capitalize if node["case"] == "capital"
|
@@ -59,14 +67,19 @@ module IsoDoc
|
|
59
67
|
refs.each_with_index do |r, i|
|
60
68
|
delim = ","
|
61
69
|
delim = ";" if r.name == "localityStack" && i>0
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
ret = eref_locality_stack(r, i, target, delim, ret)
|
71
|
+
end
|
72
|
+
ret
|
73
|
+
end
|
74
|
+
|
75
|
+
def eref_locality_stack(r, i, target, delim, ret)
|
76
|
+
if r.name == "localityStack"
|
77
|
+
r.elements.each_with_index do |rr, j|
|
78
|
+
ret += eref_localities0(rr, j, target, delim)
|
79
|
+
delim = ","
|
69
80
|
end
|
81
|
+
else
|
82
|
+
ret += eref_localities0(r, i, target, delim)
|
70
83
|
end
|
71
84
|
ret
|
72
85
|
end
|
@@ -79,7 +92,7 @@ module IsoDoc
|
|
79
92
|
end
|
80
93
|
end
|
81
94
|
|
82
|
-
|
95
|
+
# TODO: move to localization file
|
83
96
|
def eref_localities1_zh(target, type, from, to, delim)
|
84
97
|
ret = "#{delim} 第#{from.text}" if from
|
85
98
|
ret += "–#{to.text}" if to
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative "presentation_function/block"
|
2
2
|
require_relative "presentation_function/inline"
|
3
3
|
require_relative "presentation_function/section"
|
4
|
+
require_relative "presentation_function/bibdata"
|
4
5
|
|
5
6
|
module IsoDoc
|
6
7
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
@@ -14,10 +15,12 @@ module IsoDoc
|
|
14
15
|
@xrefs.parse docxml
|
15
16
|
info docxml, nil
|
16
17
|
conversions(docxml)
|
18
|
+
docxml.root["type"] = "presentation"
|
17
19
|
docxml.to_xml
|
18
20
|
end
|
19
21
|
|
20
22
|
def conversions(docxml)
|
23
|
+
bibdata docxml
|
21
24
|
section docxml
|
22
25
|
block docxml
|
23
26
|
inline docxml
|
@@ -30,6 +33,7 @@ module IsoDoc
|
|
30
33
|
end
|
31
34
|
|
32
35
|
def block(docxml)
|
36
|
+
amend docxml
|
33
37
|
table docxml
|
34
38
|
figure docxml
|
35
39
|
sourcecode docxml
|
data/lib/isodoc/version.rb
CHANGED
@@ -127,7 +127,7 @@ xmlns:m="http://schemas.microsoft.com/office/2004/12/omml">
|
|
127
127
|
def list_add(xpath, lvl)
|
128
128
|
xpath.each do |list|
|
129
129
|
(list.xpath(".//li") - list.xpath(".//ol//li | .//ul//li")).each do |l|
|
130
|
-
l.xpath("./p | ./div").each_with_index do |p, i|
|
130
|
+
l.xpath("./p | ./div | ./table").each_with_index do |p, i|
|
131
131
|
next if i == 0
|
132
132
|
p.wrap(%{<div class="ListContLevel#{lvl}"/>})
|
133
133
|
end
|
@@ -29,7 +29,7 @@ module IsoDoc::WordFunction
|
|
29
29
|
border-bottom:#{SW1} #{rowmax == totalrows ? '1.5' : '1.0'}pt;
|
30
30
|
mso-border-bottom-alt:#{SW1} #{rowmax == totalrows ? '1.5' : '1.0'}pt;
|
31
31
|
STYLE
|
32
|
-
{ rowspan: td["rowspan"], colspan: td["colspan"],
|
32
|
+
{ rowspan: td["rowspan"], colspan: td["colspan"], valign: td["valign"],
|
33
33
|
align: td["align"], style: style.gsub(/\n/, "") }
|
34
34
|
end
|
35
35
|
|
@@ -38,7 +38,8 @@ module IsoDoc::WordFunction
|
|
38
38
|
summary: node["summary"],
|
39
39
|
width: node["width"],
|
40
40
|
style: "mso-table-anchor-horizontal:column;"\
|
41
|
-
"mso-table-overlap:never;border-spacing:0;border-width:1px;#{keep_style(node)}"
|
41
|
+
"mso-table-overlap:never;border-spacing:0;border-width:1px;#{keep_style(node)}",
|
42
|
+
class: (node.text.length > 4000 ? "MsoISOTableBig" : "MsoISOTable")
|
42
43
|
}))
|
43
44
|
end
|
44
45
|
|
data/lib/isodoc/xref.rb
CHANGED
@@ -35,11 +35,15 @@ module IsoDoc::XrefGen
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def anchor_struct_xref(lbl, elem)
|
38
|
+
l10n("#{elem} #{anchor_struct_value(lbl, elem)}")
|
39
|
+
end
|
40
|
+
|
41
|
+
def anchor_struct_value(lbl, elem)
|
38
42
|
case elem
|
39
|
-
when @labels["formula"] then
|
40
|
-
when @labels["inequality"] then
|
43
|
+
when @labels["formula"] then "(#{lbl})"
|
44
|
+
when @labels["inequality"] then "(#{lbl})"
|
41
45
|
else
|
42
|
-
|
46
|
+
lbl
|
43
47
|
end
|
44
48
|
end
|
45
49
|
|
@@ -50,6 +54,7 @@ module IsoDoc::XrefGen
|
|
50
54
|
ret[:xref].gsub!(/ $/, "")
|
51
55
|
ret[:container] = @klass.get_clause_id(container) unless container.nil?
|
52
56
|
ret[:type] = type
|
57
|
+
ret[:value] = anchor_struct_value(lbl, elem)
|
53
58
|
ret
|
54
59
|
end
|
55
60
|
end
|