isodoc 2.12.0 → 2.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/isodoc.gemspec +1 -1
- data/lib/isodoc/function/blocks.rb +12 -41
- data/lib/isodoc/function/blocks_example_note.rb +37 -14
- data/lib/isodoc/function/cleanup.rb +3 -40
- data/lib/isodoc/function/inline.rb +8 -1
- data/lib/isodoc/function/lists.rb +1 -1
- data/lib/isodoc/function/references.rb +4 -128
- data/lib/isodoc/function/section.rb +1 -4
- data/lib/isodoc/function/section_titles.rb +1 -1
- data/lib/isodoc/function/table.rb +2 -2
- data/lib/isodoc/function/terms.rb +8 -10
- data/lib/isodoc/function/to_word_html.rb +3 -5
- data/lib/isodoc/function/utils.rb +1 -1
- data/lib/isodoc/init.rb +21 -0
- data/lib/isodoc/presentation_function/block.rb +58 -8
- data/lib/isodoc/presentation_function/docid.rb +101 -0
- data/lib/isodoc/presentation_function/erefs.rb +2 -2
- data/lib/isodoc/presentation_function/image.rb +31 -8
- data/lib/isodoc/presentation_function/inline.rb +5 -5
- data/lib/isodoc/presentation_function/math.rb +0 -14
- data/lib/isodoc/presentation_function/metadata.rb +0 -62
- data/lib/isodoc/presentation_function/refs.rb +44 -14
- data/lib/isodoc/presentation_function/section.rb +12 -15
- data/lib/isodoc/presentation_function/terms.rb +27 -1
- data/lib/isodoc/presentation_xml_convert.rb +4 -1
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +3 -3
- data/lib/isodoc/xref/clause_order.rb +2 -2
- data/lib/isodoc/xref/xref_sect_gen.rb +7 -22
- data/lib/isodoc/xref/xref_util.rb +6 -0
- metadata +5 -4
@@ -16,8 +16,6 @@ module IsoDoc
|
|
16
16
|
def prefix_name(node, delim, number, elem)
|
17
17
|
number.nil? || number.empty? and return
|
18
18
|
unless name = node.at(ns("./#{elem}"))
|
19
|
-
#(node.children.empty? and node.add_child("<#{elem}></#{elem}>")) or
|
20
|
-
# node.children.first.previous = "<#{elem}></#{elem}>"
|
21
19
|
node.add_first_child "<#{elem}></#{elem}>"
|
22
20
|
name = node.children.first
|
23
21
|
end
|
@@ -33,7 +31,7 @@ module IsoDoc
|
|
33
31
|
def formula1(elem)
|
34
32
|
formula_where(elem.at(ns("./dl")))
|
35
33
|
lbl = @xrefs.anchor(elem["id"], :label, false)
|
36
|
-
prefix_name(elem, "", lbl, "name")
|
34
|
+
lbl.nil? || lbl.empty? or prefix_name(elem, "", "(#{lbl})", "name")
|
37
35
|
end
|
38
36
|
|
39
37
|
def formula_where(dlist)
|
@@ -60,14 +58,23 @@ module IsoDoc
|
|
60
58
|
docxml.xpath(ns("//note")).each { |f| note1(f) }
|
61
59
|
end
|
62
60
|
|
61
|
+
def note_delim(_elem)
|
62
|
+
""
|
63
|
+
end
|
64
|
+
|
63
65
|
def note1(elem)
|
64
66
|
%w(bibdata bibitem).include?(elem.parent.name) ||
|
65
67
|
elem["notag"] == "true" and return
|
68
|
+
lbl = note_label(elem)
|
69
|
+
prefix_name(elem, "", lbl, "name")
|
70
|
+
end
|
71
|
+
|
72
|
+
def note_label(elem)
|
66
73
|
n = @xrefs.get[elem["id"]]
|
67
74
|
lbl = @i18n.note
|
68
75
|
(n.nil? || n[:label].nil? || n[:label].empty?) or
|
69
76
|
lbl = l10n("#{lbl} #{n[:label]}")
|
70
|
-
|
77
|
+
"#{lbl}#{note_delim(elem)}"
|
71
78
|
end
|
72
79
|
|
73
80
|
def admonition(docxml)
|
@@ -77,16 +84,29 @@ module IsoDoc
|
|
77
84
|
def admonition1(elem)
|
78
85
|
if elem["type"] == "box"
|
79
86
|
admonition_numbered1(elem)
|
87
|
+
elsif elem["notag"] == "true" || elem.at(ns("./name"))
|
80
88
|
else
|
81
|
-
|
82
|
-
prefix_name(elem, "",
|
89
|
+
label = admonition_label(elem, nil)
|
90
|
+
prefix_name(elem, "", label, "name")
|
83
91
|
end
|
92
|
+
n = elem.at(ns("./name")) and n << admonition_delim(elem)
|
84
93
|
end
|
85
94
|
|
86
95
|
def admonition_numbered1(elem)
|
87
96
|
elem["unnumbered"] && !elem.at(ns("./name")) and return
|
88
|
-
|
89
|
-
prefix_name(elem, block_delim,
|
97
|
+
label = admonition_label(elem, @xrefs.anchor(elem["id"], :label, false))
|
98
|
+
prefix_name(elem, block_delim, label, "name")
|
99
|
+
end
|
100
|
+
|
101
|
+
def admonition_label(elem, num)
|
102
|
+
lbl = if elem["type"] == "box" then @i18n.box
|
103
|
+
else @i18n.admonition[elem["type"]]&.upcase end
|
104
|
+
num and lbl = l10n("#{lbl} #{num}")
|
105
|
+
lbl
|
106
|
+
end
|
107
|
+
|
108
|
+
def admonition_delim(_elem)
|
109
|
+
""
|
90
110
|
end
|
91
111
|
|
92
112
|
def table(docxml)
|
@@ -95,6 +115,7 @@ module IsoDoc
|
|
95
115
|
end
|
96
116
|
|
97
117
|
def table1(elem)
|
118
|
+
table_fn(elem)
|
98
119
|
labelled_ancestor(elem) and return
|
99
120
|
elem["unnumbered"] && !elem.at(ns("./name")) and return
|
100
121
|
n = @xrefs.anchor(elem["id"], :label, false)
|
@@ -113,6 +134,15 @@ module IsoDoc
|
|
113
134
|
end
|
114
135
|
end
|
115
136
|
|
137
|
+
def table_fn(elem)
|
138
|
+
(elem.xpath(ns(".//fn")) - elem.xpath(ns("./name//fn")))
|
139
|
+
.each_with_index do |f, i|
|
140
|
+
table_fn1(elem, f, i)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def table_fn1(table, fnote, idx); end
|
145
|
+
|
116
146
|
# we use this to eliminate the semantic amend blocks from rendering
|
117
147
|
def amend(docxml)
|
118
148
|
docxml.xpath(ns("//amend")).each { |f| amend1(f) }
|
@@ -126,6 +156,8 @@ module IsoDoc
|
|
126
156
|
elem.replace(elem.children)
|
127
157
|
end
|
128
158
|
|
159
|
+
def dl(docxml); end
|
160
|
+
|
129
161
|
def ol(docxml)
|
130
162
|
docxml.xpath(ns("//ol")).each { |f| ol1(f) }
|
131
163
|
@xrefs.list_anchor_names(docxml.xpath(ns(@xrefs.sections_xpath)))
|
@@ -182,5 +214,23 @@ module IsoDoc
|
|
182
214
|
def source_modification(mod)
|
183
215
|
termsource_modification(mod.parent)
|
184
216
|
end
|
217
|
+
|
218
|
+
def quote(docxml)
|
219
|
+
docxml.xpath(ns("//quote")).each { |f| quote1(f) }
|
220
|
+
end
|
221
|
+
|
222
|
+
def quote1(elem)
|
223
|
+
author = elem.at(ns("./author"))
|
224
|
+
source = elem.at(ns("./source"))
|
225
|
+
author.nil? && source.nil? and return
|
226
|
+
p = "— "
|
227
|
+
p += author.remove.to_xml if author
|
228
|
+
p += ", " if author && source
|
229
|
+
if source
|
230
|
+
source.name = "eref"
|
231
|
+
p += source.remove.to_xml
|
232
|
+
end
|
233
|
+
elem << "<attribution><p>#{l10n p}</p></attribution>"
|
234
|
+
end
|
185
235
|
end
|
186
236
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module IsoDoc
|
2
|
+
class PresentationXMLConvert < ::IsoDoc::Convert
|
3
|
+
def docid_prefixes(docxml)
|
4
|
+
docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
|
5
|
+
i.children = docid_prefix(i["type"], to_xml(i.children))
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
=begin
|
10
|
+
# This is highly specific to ISO, but it's not a bad precedent for
|
11
|
+
# references anyway; keeping here instead of in IsoDoc::Iso for now
|
12
|
+
def docid_l10n(text)
|
13
|
+
text.nil? and return text
|
14
|
+
@i18n.all_parts and text.gsub!(/All Parts/i, @i18n.all_parts.downcase)
|
15
|
+
text.size < 20 and text.gsub!(/ /, " ")
|
16
|
+
text
|
17
|
+
end
|
18
|
+
|
19
|
+
def docid_prefix(prefix, docid)
|
20
|
+
docid = "#{prefix} #{docid}" if prefix && !omit_docid_prefix(prefix) &&
|
21
|
+
!/^#{prefix}\b/.match(docid)
|
22
|
+
docid_l10n(docid)
|
23
|
+
end
|
24
|
+
|
25
|
+
def omit_docid_prefix(prefix)
|
26
|
+
prefix.nil? || prefix.empty? and return true
|
27
|
+
%w(ISO IEC IEV ITU W3C BIPM csd metanorma repository metanorma-ordinal)
|
28
|
+
.include? prefix
|
29
|
+
end
|
30
|
+
=end
|
31
|
+
|
32
|
+
def pref_ref_code(bib)
|
33
|
+
bib["suppress_identifier"] == "true" and return nil
|
34
|
+
ret = bib.xpath(ns("./docidentifier[@scope = 'biblio-tag']"))
|
35
|
+
ret.empty? or return ret.map(&:text)
|
36
|
+
ret = pref_ref_code_parse(bib) or return nil
|
37
|
+
ins = bib.at(ns("./docidentifier[last()]"))
|
38
|
+
ret.reverse_each do |r|
|
39
|
+
ins.next = "<docidentifier scope='biblio-tag'>#{docid_l10n(r)}</docidentifier>"
|
40
|
+
end
|
41
|
+
ret
|
42
|
+
end
|
43
|
+
|
44
|
+
def pref_ref_code_parse(bib)
|
45
|
+
data, = @bibrender.parse(bib)
|
46
|
+
ret = data[:authoritative_identifier] or return nil
|
47
|
+
ret.empty? and return nil
|
48
|
+
ret
|
49
|
+
end
|
50
|
+
|
51
|
+
# returns [metanorma, non-metanorma, DOI/ISSN/ISBN] identifiers
|
52
|
+
def bibitem_ref_code(bib)
|
53
|
+
id, id1, id2, id3 = bibitem_ref_code_prep(bib)
|
54
|
+
id || id1 || id2 || id3 and return [id, id1, id2, id3]
|
55
|
+
bib["suppress_identifier"] == "true" and return [nil, nil, nil, nil]
|
56
|
+
[nil, no_identifier(bib), nil, nil]
|
57
|
+
end
|
58
|
+
|
59
|
+
def bibitem_ref_code_prep(bib)
|
60
|
+
id = bib.at(ns("./docidentifier[@type = 'metanorma']"))
|
61
|
+
id1 = pref_ref_code(bib)
|
62
|
+
id2 = bib.at(ns("./docidentifier[#{SKIP_DOCID}]"))
|
63
|
+
id3 = bib.at(ns("./docidentifier[@type = 'metanorma-ordinal']"))
|
64
|
+
[id, id1, id2, id3]
|
65
|
+
end
|
66
|
+
|
67
|
+
def no_identifier(bib)
|
68
|
+
@i18n.no_identifier or return nil
|
69
|
+
id = Nokogiri::XML::Node.new("docidentifier", bib.document)
|
70
|
+
id << @i18n.no_identifier
|
71
|
+
id
|
72
|
+
end
|
73
|
+
|
74
|
+
def bracket_if_num(num)
|
75
|
+
num.nil? and return nil
|
76
|
+
num = num.text.sub(/^\[/, "").sub(/\]$/, "")
|
77
|
+
/^\d+$/.match?(num) and return "[#{num}]"
|
78
|
+
num
|
79
|
+
end
|
80
|
+
|
81
|
+
def unbracket1(ident)
|
82
|
+
ident.nil? and return nil
|
83
|
+
ident.is_a?(String) or ident = ident.text
|
84
|
+
ident.sub(/^\[/, "").sub(/\]$/, "")
|
85
|
+
end
|
86
|
+
|
87
|
+
def unbracket(ident)
|
88
|
+
if ident.respond_to?(:size)
|
89
|
+
ident.map { |x| unbracket1(x) }.join(" / ")
|
90
|
+
else unbracket1(ident)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def render_identifier(ident)
|
95
|
+
{ metanorma: bracket_if_num(ident[0]),
|
96
|
+
sdo: unbracket(ident[1]),
|
97
|
+
doi: unbracket(ident[2]),
|
98
|
+
ordinal: bracket_if_num(ident[3]) }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -3,7 +3,7 @@ require "metanorma-utils"
|
|
3
3
|
module IsoDoc
|
4
4
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
5
5
|
def citeas(xmldoc)
|
6
|
-
xmldoc.xpath(ns("//eref | //origin | //quote
|
6
|
+
xmldoc.xpath(ns("//eref | //origin | //quote//source")).each do |e|
|
7
7
|
e["bibitemid"] && e["citeas"] or next
|
8
8
|
a = @xrefs.anchor(e["bibitemid"], :xref, false) and e["citeas"] = a
|
9
9
|
end
|
@@ -178,7 +178,7 @@ module IsoDoc
|
|
178
178
|
end
|
179
179
|
|
180
180
|
def eref2link(docxml)
|
181
|
-
docxml.xpath(ns("//eref | //origin[not(termref)] | //quote
|
181
|
+
docxml.xpath(ns("//eref | //origin[not(termref)] | //quote//source"))
|
182
182
|
.each do |e|
|
183
183
|
href = eref_target(e) or next
|
184
184
|
e.xpath(ns("./locality | ./localityStack")).each(&:remove)
|
@@ -46,6 +46,8 @@ module IsoDoc
|
|
46
46
|
def figure1(elem)
|
47
47
|
elem["class"] == "pseudocode" || elem["type"] == "pseudocode" and
|
48
48
|
return sourcecode1(elem)
|
49
|
+
figure_fn(elem)
|
50
|
+
figure_key(elem.at(ns("./dl")))
|
49
51
|
figure_label?(elem) or return nil
|
50
52
|
lbl = @xrefs.anchor(elem["id"], :label, false) or return
|
51
53
|
# no xref, no label: this can be set in xref
|
@@ -53,6 +55,24 @@ module IsoDoc
|
|
53
55
|
l10n("#{figure_label(elem)} #{lbl}"), "name")
|
54
56
|
end
|
55
57
|
|
58
|
+
# move footnotes into key, and get rid of footnote reference
|
59
|
+
# since it is in diagram
|
60
|
+
def figure_fn(elem)
|
61
|
+
fn = elem.xpath(ns(".//fn")) - elem.xpath(ns("./name//fn"))
|
62
|
+
fn.empty? and return
|
63
|
+
dl = figure_key_insert_pt(elem)
|
64
|
+
fn.each do |f|
|
65
|
+
dl.previous = "<dt><p><sup>#{f['reference']}</sup></p></dt>" \
|
66
|
+
"<dd>#{f.remove.children.to_xml}</dd>"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def figure_key_insert_pt(elem)
|
71
|
+
elem.at(ns("//dl/name"))&.next ||
|
72
|
+
elem.at(ns("//dl"))&.children&.first ||
|
73
|
+
elem.add_child("<dl> </dl>").first.children.first
|
74
|
+
end
|
75
|
+
|
56
76
|
def figure_label?(elem)
|
57
77
|
elem.at(ns("./figure")) && !elem.at(ns("./name")) and return false
|
58
78
|
true
|
@@ -64,6 +84,14 @@ module IsoDoc
|
|
64
84
|
lower2cap klasslbl
|
65
85
|
end
|
66
86
|
|
87
|
+
def figure_key(dlist)
|
88
|
+
dlist or return
|
89
|
+
dlist["class"] = "formula_dl"
|
90
|
+
dlist.at(ns("./name")) and return
|
91
|
+
dlist.previous =
|
92
|
+
"<p keep-with-next='true'><strong>#{@i18n.key}</strong></p>"
|
93
|
+
end
|
94
|
+
|
67
95
|
def eps2svg(img)
|
68
96
|
return unless eps?(img["mimetype"])
|
69
97
|
|
@@ -77,7 +105,7 @@ module IsoDoc
|
|
77
105
|
def svg_emf_double(img)
|
78
106
|
if emf?(img["mimetype"])
|
79
107
|
img = emf_encode(img)
|
80
|
-
#img.children.first.previous = emf_to_svg(img)
|
108
|
+
# img.children.first.previous = emf_to_svg(img)
|
81
109
|
img.add_first_child emf_to_svg(img)
|
82
110
|
elsif img["mimetype"] == "image/svg+xml"
|
83
111
|
src = svg_to_emf(img) or return
|
@@ -127,16 +155,11 @@ module IsoDoc
|
|
127
155
|
|
128
156
|
def svg_to_emf(node)
|
129
157
|
@output_formats[:doc] or return
|
130
|
-
|
131
158
|
svg_impose_height_attr(node)
|
132
|
-
|
133
|
-
if node.elements&.first&.name == "svg" || %r{^data:}.match?(node["src"])
|
159
|
+
node.elements&.first&.name == "svg" || %r{^data:}.match?(node["src"]) and
|
134
160
|
return svg_to_emf_from_node(node)
|
135
|
-
end
|
136
|
-
|
137
161
|
target_path = imgfile_suffix(node["src"], "emf")
|
138
|
-
|
139
|
-
|
162
|
+
File.exist?(target_path) and return target_path
|
140
163
|
svg_to_emf_from_node(node, target_path)
|
141
164
|
end
|
142
165
|
|
@@ -54,8 +54,8 @@ module IsoDoc
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def quotesource(docxml)
|
57
|
-
docxml.xpath(ns("//quote
|
58
|
-
docxml.xpath(ns("//quote
|
57
|
+
docxml.xpath(ns("//quote//source")).each { |f| xref1(f) }
|
58
|
+
docxml.xpath(ns("//quote//source//xref")).each do |f|
|
59
59
|
f.replace(f.children)
|
60
60
|
end
|
61
61
|
end
|
@@ -164,9 +164,9 @@ module IsoDoc
|
|
164
164
|
def passthrough1(elem, formats)
|
165
165
|
(elem["formats"] && !elem["formats"].empty?) or elem["formats"] = "all"
|
166
166
|
f = elem["formats"].split(",")
|
167
|
-
(f - formats).size == f.size or
|
168
|
-
|
169
|
-
elem["formats"] = "
|
167
|
+
(f - formats).size == f.size or f = "all"
|
168
|
+
f == ["all"] and f = formats.dup
|
169
|
+
elem["formats"] = " #{f.join(' ')} "
|
170
170
|
end
|
171
171
|
|
172
172
|
def extract_custom_charsets(docxml)
|
@@ -7,7 +7,6 @@ module IsoDoc
|
|
7
7
|
MATHML = { "m" => "http://www.w3.org/1998/Math/MathML" }.freeze
|
8
8
|
|
9
9
|
def mathml(docxml)
|
10
|
-
docxml.xpath("//m:math", MATHML).each { |f| mathml_linebreak(f) }
|
11
10
|
locale = @lang.to_sym
|
12
11
|
@numfmt = Plurimath::NumberFormatter
|
13
12
|
.new(locale, localize_number: @localizenumber,
|
@@ -160,19 +159,6 @@ module IsoDoc
|
|
160
159
|
mathml_number(node, locale)
|
161
160
|
end
|
162
161
|
|
163
|
-
def mathml_linebreak(node)
|
164
|
-
node.at(".//*/@linebreak") or return
|
165
|
-
m = Plurimath::Math.parse(node.to_xml, :mathml)
|
166
|
-
.to_mathml(split_on_linebreak: true)
|
167
|
-
ret = Nokogiri::XML("<m>#{m}</m>").root
|
168
|
-
ret.elements.each_with_index do |e, i|
|
169
|
-
i.zero? or e.previous = "<br/>"
|
170
|
-
end
|
171
|
-
node.replace(<<~OUTPUT)
|
172
|
-
<math-with-linebreak>#{ret.children}</math-with-linebreak><math-no-linebreak>#{node.to_xml}</math-no-linebreak>
|
173
|
-
OUTPUT
|
174
|
-
end
|
175
|
-
|
176
162
|
# convert any Ascii superscripts to correct(ish) MathML
|
177
163
|
# Not bothering to match times, base of 1.0 x 10^-20, just ^-20
|
178
164
|
def mn_to_msup(node)
|
@@ -4,7 +4,6 @@ module IsoDoc
|
|
4
4
|
toc_metadata(docxml)
|
5
5
|
fonts_metadata(docxml)
|
6
6
|
attachments_extract(docxml)
|
7
|
-
preprocess_xslt_insert(docxml)
|
8
7
|
localized_strings(docxml)
|
9
8
|
a = docxml.at(ns("//metanorma-extension")) or return
|
10
9
|
a.elements.empty? and a.remove
|
@@ -83,67 +82,6 @@ module IsoDoc
|
|
83
82
|
"</presentation-metadata>"
|
84
83
|
end
|
85
84
|
|
86
|
-
def preprocess_xslt_insert(docxml)
|
87
|
-
content = ""
|
88
|
-
p = passthrough_xslt and content += p
|
89
|
-
p = preprocess_xslt_read and content += File.read(p)
|
90
|
-
content.empty? and return
|
91
|
-
ins = extension_insert(docxml, %w(render))
|
92
|
-
ins << content
|
93
|
-
end
|
94
|
-
|
95
|
-
COPY_XSLT =
|
96
|
-
'<xsl:copy><xsl:apply-templates select="@* | node()"/></xsl:copy>'.freeze
|
97
|
-
COPY_CHILDREN_XSLT =
|
98
|
-
'<xsl:apply-templates select="node()"/>'.freeze
|
99
|
-
|
100
|
-
def xslt_template(content)
|
101
|
-
<<~XSLT
|
102
|
-
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
|
103
|
-
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no"/>
|
104
|
-
<xsl:template match="@* | node()">#{COPY_XSLT}</xsl:template>
|
105
|
-
#{content}
|
106
|
-
</xsl:stylesheet>
|
107
|
-
XSLT
|
108
|
-
end
|
109
|
-
|
110
|
-
def passthrough_xslt
|
111
|
-
@output_formats.nil? and return nil
|
112
|
-
@output_formats.empty? and return nil
|
113
|
-
@output_formats.each_key.with_object([]) do |k, m|
|
114
|
-
m << <<~XSLT
|
115
|
-
<preprocess-xslt format="#{k}">
|
116
|
-
#{xslt_template(<<~XSLT1)
|
117
|
-
<xsl:template match="*[local-name() = 'passthrough']">
|
118
|
-
<xsl:if test="contains(@formats,',#{k},')"> <!-- delimited -->
|
119
|
-
#{COPY_XSLT}
|
120
|
-
</xsl:if>
|
121
|
-
</xsl:template>
|
122
|
-
XSLT1
|
123
|
-
}
|
124
|
-
</preprocess-xslt>
|
125
|
-
XSLT
|
126
|
-
m << <<~XSLT
|
127
|
-
<preprocess-xslt format="#{k}">
|
128
|
-
#{xslt_template(<<~XSLT1)
|
129
|
-
<xsl:template match="*[local-name() = 'math-with-linebreak']">
|
130
|
-
#{k == 'pdf' ? COPY_CHILDREN_XSLT : ''}
|
131
|
-
</xsl:template>
|
132
|
-
<xsl:template match="*[local-name() = 'math-no-linebreak']">
|
133
|
-
#{k == 'pdf' ? '' : COPY_CHILDREN_XSLT}
|
134
|
-
</xsl:template>
|
135
|
-
XSLT1
|
136
|
-
}
|
137
|
-
</preprocess-xslt>
|
138
|
-
XSLT
|
139
|
-
end.join("\n")
|
140
|
-
end
|
141
|
-
|
142
|
-
# read in from file, but with `<preprocess-xslt @format="">` wrapper
|
143
|
-
def preprocess_xslt_read
|
144
|
-
html_doc_path("preprocess.xslt")
|
145
|
-
end
|
146
|
-
|
147
85
|
def i18n_tag(key, value)
|
148
86
|
"<localized-string key='#{key}' language='#{@lang}'>#{value}" \
|
149
87
|
"</localized-string>"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative "docid"
|
2
|
+
|
1
3
|
module IsoDoc
|
2
4
|
class PresentationXMLConvert < ::IsoDoc::Convert
|
3
5
|
def references(docxml)
|
@@ -5,10 +7,24 @@ module IsoDoc
|
|
5
7
|
renderings = references_render(docxml)
|
6
8
|
docxml.xpath(ns("//references/bibitem")).each do |x|
|
7
9
|
bibitem(x, renderings)
|
10
|
+
reference_name(x)
|
8
11
|
end
|
9
12
|
hidden_items(docxml)
|
10
13
|
move_norm_ref_to_sections(docxml)
|
11
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
def reference_names(docxml)
|
17
|
+
docxml.xpath(ns("//bibitem[not(ancestor::bibitem)]")).each do |ref|
|
18
|
+
reference_name(ref)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def reference_name(ref)
|
23
|
+
ids = bibitem_ref_code(ref)
|
24
|
+
identifiers = render_identifier(ids)
|
25
|
+
reference = docid_l10n(identifiers[:metanorma] || identifiers[:sdo] ||
|
26
|
+
identifiers[:ordinal] || identifiers[:doi])
|
27
|
+
@xrefs.get[ref["id"]] = { xref: reference }
|
12
28
|
end
|
13
29
|
|
14
30
|
def move_norm_ref_to_sections(docxml)
|
@@ -56,7 +72,7 @@ module IsoDoc
|
|
56
72
|
end
|
57
73
|
|
58
74
|
def bibitem(xml, renderings)
|
59
|
-
|
75
|
+
implicit_reference(xml) and xml["hidden"] = "true"
|
60
76
|
bibrender_item(xml, renderings)
|
61
77
|
end
|
62
78
|
|
@@ -81,7 +97,7 @@ module IsoDoc
|
|
81
97
|
end
|
82
98
|
|
83
99
|
def bibliography_bibitem_number_skip(bibitem)
|
84
|
-
|
100
|
+
implicit_reference(bibitem) ||
|
85
101
|
bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) ||
|
86
102
|
bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
|
87
103
|
bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
|
@@ -92,7 +108,7 @@ module IsoDoc
|
|
92
108
|
docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
|
93
109
|
i = bibliography_bibitem_number1(b, i)
|
94
110
|
end
|
95
|
-
|
111
|
+
reference_names docxml
|
96
112
|
bibliography_bibitem_tag(docxml)
|
97
113
|
end
|
98
114
|
|
@@ -122,12 +138,6 @@ module IsoDoc
|
|
122
138
|
ins
|
123
139
|
end
|
124
140
|
|
125
|
-
def docid_prefixes(docxml)
|
126
|
-
docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
|
127
|
-
i.children = @xrefs.klass.docid_prefix(i["type"], to_xml(i.children))
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
141
|
def bibliography_bibitem_tag(docxml)
|
132
142
|
[true, false].each do |norm|
|
133
143
|
i = 0
|
@@ -139,17 +149,17 @@ module IsoDoc
|
|
139
149
|
|
140
150
|
def bibliography_bibitem_tag1(ref, idx, norm)
|
141
151
|
ref.xpath(ns("./bibitem")).each do |b|
|
142
|
-
|
152
|
+
implicit_reference(b) and next
|
143
153
|
idx += 1 unless b["hidden"]
|
144
|
-
insert_biblio_tag(b, idx, !norm,
|
154
|
+
insert_biblio_tag(b, idx, !norm, standard?(b))
|
145
155
|
end
|
146
156
|
idx
|
147
157
|
end
|
148
158
|
|
149
159
|
def insert_biblio_tag(bib, ordinal, biblio, standard)
|
150
160
|
datefn = date_note_process(bib)
|
151
|
-
ids =
|
152
|
-
idents =
|
161
|
+
ids = bibitem_ref_code(bib)
|
162
|
+
idents = render_identifier(ids)
|
153
163
|
ret = if biblio then biblio_ref_entry_code(ordinal, idents, ids,
|
154
164
|
standard, datefn, bib)
|
155
165
|
else norm_ref_entry_code(ordinal, idents, ids, standard, datefn,
|
@@ -199,5 +209,25 @@ module IsoDoc
|
|
199
209
|
ret = bib.at(ns("./docidentifier//fn")) or return ""
|
200
210
|
to_xml(ret.remove)
|
201
211
|
end
|
212
|
+
|
213
|
+
# reference not to be rendered because it is deemed implicit
|
214
|
+
# in the standards environment
|
215
|
+
def implicit_reference(bib)
|
216
|
+
bib["hidden"] == "true"
|
217
|
+
end
|
218
|
+
|
219
|
+
SKIP_DOCID = <<~XPATH.strip.freeze
|
220
|
+
@type = 'DOI' or @type = 'doi' or @type = 'ISSN' or @type = 'issn' or @type = 'ISBN' or @type = 'isbn' or starts-with(@type, 'ISSN.') or starts-with(@type, 'ISBN.') or starts-with(@type, 'issn.') or starts-with(@type, 'isbn.')
|
221
|
+
XPATH
|
222
|
+
|
223
|
+
def standard?(bib)
|
224
|
+
ret = false
|
225
|
+
bib.xpath(ns("./docidentifier")).each do |id|
|
226
|
+
id["type"].nil? ||
|
227
|
+
id.at(".//self::*[#{SKIP_DOCID} or @type = 'metanorma']") and next
|
228
|
+
ret = true
|
229
|
+
end
|
230
|
+
ret
|
231
|
+
end
|
202
232
|
end
|
203
233
|
end
|
@@ -9,9 +9,18 @@ module IsoDoc
|
|
9
9
|
s.add_first_child "<p class='zzSTDTitle1'>#{t}</p>"
|
10
10
|
end
|
11
11
|
|
12
|
+
def missing_title(docxml)
|
13
|
+
docxml.xpath(ns("//definitions[not(./title)]")).each do |d|
|
14
|
+
# should only be happening for subclauses
|
15
|
+
d.add_first_child "<title>#{@i18n.symbols}</title>"
|
16
|
+
end
|
17
|
+
docxml.xpath(ns("//foreword[not(./title)]")).each do |d|
|
18
|
+
d.add_first_child "<title>#{@i18n.foreword}</title>"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
12
22
|
def clause(docxml)
|
13
|
-
docxml.xpath(ns("//clause | "
|
14
|
-
"//terms | //definitions | //references"))
|
23
|
+
docxml.xpath(ns("//clause | //terms | //definitions | //references"))
|
15
24
|
.each do |f|
|
16
25
|
f.parent.name == "annex" &&
|
17
26
|
@xrefs.klass.single_term_clause?(f.parent) and next
|
@@ -87,17 +96,6 @@ module IsoDoc
|
|
87
96
|
end
|
88
97
|
end
|
89
98
|
|
90
|
-
def term(docxml)
|
91
|
-
docxml.xpath(ns("//term")).each do |f|
|
92
|
-
term1(f)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def term1(elem)
|
97
|
-
lbl = @xrefs.anchor(elem["id"], :label) or return
|
98
|
-
prefix_name(elem, "", "#{lbl}#{clausedelim}", "name")
|
99
|
-
end
|
100
|
-
|
101
99
|
def index(docxml)
|
102
100
|
docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove)
|
103
101
|
end
|
@@ -207,8 +205,7 @@ module IsoDoc
|
|
207
205
|
if prev.name == "floating-title"
|
208
206
|
ret << prev
|
209
207
|
p = prev
|
210
|
-
else break
|
211
|
-
end
|
208
|
+
else break end
|
212
209
|
end
|
213
210
|
ret
|
214
211
|
end
|
@@ -109,11 +109,20 @@ module IsoDoc
|
|
109
109
|
docxml.xpath(ns("//termnote")).each { |f| termnote1(f) }
|
110
110
|
end
|
111
111
|
|
112
|
+
def termnote_delim(_elem)
|
113
|
+
l10n(": ")
|
114
|
+
end
|
115
|
+
|
112
116
|
def termnote1(elem)
|
113
|
-
lbl =
|
117
|
+
lbl = termnote_label(elem)
|
114
118
|
prefix_name(elem, "", lower2cap(lbl), "name")
|
115
119
|
end
|
116
120
|
|
121
|
+
def termnote_label(elem)
|
122
|
+
lbl = @xrefs.anchor(elem["id"], :label) || "???"
|
123
|
+
l10n "#{lbl}#{termnote_delim(elem)}"
|
124
|
+
end
|
125
|
+
|
117
126
|
def termdefinition(docxml)
|
118
127
|
docxml.xpath(ns("//term[definition]")).each do |f|
|
119
128
|
termdefinition1(f)
|
@@ -123,6 +132,7 @@ module IsoDoc
|
|
123
132
|
def termdefinition1(elem)
|
124
133
|
unwrap_definition(elem)
|
125
134
|
multidef(elem) if elem.xpath(ns("./definition")).size > 1
|
135
|
+
termdomain(elem)
|
126
136
|
end
|
127
137
|
|
128
138
|
def multidef(elem)
|
@@ -144,6 +154,13 @@ module IsoDoc
|
|
144
154
|
end
|
145
155
|
end
|
146
156
|
|
157
|
+
def termdomain(elem)
|
158
|
+
d = elem.at(ns(".//domain")) or return
|
159
|
+
p = elem.at(ns(".//definition//p")) or return
|
160
|
+
p.add_first_child "<#{d.to_xml}> "
|
161
|
+
d["hidden"] = true
|
162
|
+
end
|
163
|
+
|
147
164
|
def termsource(docxml)
|
148
165
|
docxml.xpath(ns("//termsource")).each { |f| termsource_modification(f) }
|
149
166
|
docxml.xpath(ns("//termsource")).each { |f| termsource1(f) }
|
@@ -176,5 +193,14 @@ module IsoDoc
|
|
176
193
|
when "adapted" then @i18n.adapted
|
177
194
|
end
|
178
195
|
end
|
196
|
+
|
197
|
+
def term(docxml)
|
198
|
+
docxml.xpath(ns("//term")).each { |f| term1(f) }
|
199
|
+
end
|
200
|
+
|
201
|
+
def term1(elem)
|
202
|
+
lbl = @xrefs.anchor(elem["id"], :label) or return
|
203
|
+
prefix_name(elem, "", "#{lbl}#{clausedelim}", "name")
|
204
|
+
end
|
179
205
|
end
|
180
206
|
end
|