isodoc 1.0.24 → 1.0.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +14 -4
- data/.github/workflows/ubuntu.yml +19 -5
- data/.github/workflows/windows.yml +14 -4
- data/isodoc.gemspec +1 -1
- data/lib/isodoc-yaml/i18n-en.yaml +3 -1
- data/lib/isodoc-yaml/i18n-fr.yaml +3 -1
- data/lib/isodoc-yaml/i18n-zh-Hans.yaml +3 -1
- data/lib/isodoc/convert.rb +1 -0
- data/lib/isodoc/function/blocks.rb +43 -49
- data/lib/isodoc/function/{blocks_example.rb → blocks_example_note.rb} +57 -2
- data/lib/isodoc/function/cleanup.rb +16 -2
- data/lib/isodoc/function/i18n.rb +1 -0
- data/lib/isodoc/function/inline.rb +79 -77
- data/lib/isodoc/function/inline_simple.rb +72 -0
- data/lib/isodoc/function/lists.rb +12 -6
- data/lib/isodoc/function/references.rb +51 -39
- data/lib/isodoc/function/reqt.rb +13 -4
- data/lib/isodoc/function/section.rb +19 -8
- data/lib/isodoc/function/table.rb +3 -4
- data/lib/isodoc/function/terms.rb +1 -1
- data/lib/isodoc/function/to_word_html.rb +23 -13
- data/lib/isodoc/function/utils.rb +13 -6
- data/lib/isodoc/function/xref_counter.rb +43 -9
- data/lib/isodoc/function/xref_gen.rb +2 -1
- data/lib/isodoc/function/xref_gen_seq.rb +11 -10
- data/lib/isodoc/function/xref_sect_gen.rb +24 -24
- data/lib/isodoc/headlesshtml_convert.rb +5 -0
- data/lib/isodoc/html_convert.rb +5 -0
- data/lib/isodoc/html_function/footnotes.rb +3 -3
- data/lib/isodoc/html_function/html.rb +16 -1
- data/lib/isodoc/html_function/postprocess.rb +6 -5
- data/lib/isodoc/metadata.rb +10 -3
- data/lib/isodoc/metadata_date.rb +19 -7
- data/lib/isodoc/pdf_convert.rb +5 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_convert.rb +5 -0
- data/lib/isodoc/word_function/body.rb +13 -51
- data/lib/isodoc/word_function/footnotes.rb +3 -3
- data/lib/isodoc/word_function/inline.rb +75 -0
- data/lib/isodoc/word_function/postprocess.rb +13 -2
- data/lib/isodoc/word_function/table.rb +3 -3
- data/lib/isodoc/xslfo_convert.rb +5 -0
- data/spec/assets/i18n.yaml +4 -1
- data/spec/assets/odf.emf +0 -0
- data/spec/assets/odf.svg +4 -0
- data/spec/assets/odf1.svg +4 -0
- data/spec/isodoc/blocks_spec.rb +274 -51
- data/spec/isodoc/cleanup_spec.rb +317 -25
- data/spec/isodoc/footnotes_spec.rb +20 -5
- data/spec/isodoc/i18n_spec.rb +12 -12
- data/spec/isodoc/inline_spec.rb +299 -4
- data/spec/isodoc/lists_spec.rb +8 -8
- data/spec/isodoc/metadata_spec.rb +112 -3
- data/spec/isodoc/postproc_spec.rb +39 -21
- data/spec/isodoc/ref_spec.rb +121 -52
- data/spec/isodoc/section_spec.rb +236 -207
- data/spec/isodoc/table_spec.rb +28 -28
- data/spec/isodoc/terms_spec.rb +57 -13
- data/spec/isodoc/xref_spec.rb +218 -71
- metadata +10 -5
@@ -1,13 +1,25 @@
|
|
1
1
|
module IsoDoc::Function
|
2
2
|
module Cleanup
|
3
3
|
def textcleanup(docxml)
|
4
|
+
docxml = termref_cleanup(passthrough_cleanup(docxml))
|
5
|
+
end
|
6
|
+
|
7
|
+
def termref_cleanup(docxml)
|
4
8
|
docxml.
|
9
|
+
gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, "; ").
|
5
10
|
gsub(/\[TERMREF\]\s*/, l10n("[#{@source_lbl}: ")).
|
6
11
|
gsub(/\s*\[MODIFICATION\]\s*\[\/TERMREF\]/, l10n(", #{@modified_lbl} [/TERMREF]")).
|
7
|
-
gsub(
|
12
|
+
gsub(%r{\s*\[\/TERMREF\]\s*}, l10n("]")).
|
8
13
|
gsub(/\s*\[MODIFICATION\]/, l10n(", #{@modified_lbl} — "))
|
9
14
|
end
|
10
15
|
|
16
|
+
def passthrough_cleanup(docxml)
|
17
|
+
docxml.split(%r{(<passthrough>|</passthrough>)}).each_slice(4).map do |a|
|
18
|
+
a.size > 2 and a[2] = HTMLEntities.new.decode(a[2])
|
19
|
+
[a[0], a[2]]
|
20
|
+
end.join
|
21
|
+
end
|
22
|
+
|
11
23
|
def cleanup(docxml)
|
12
24
|
comment_cleanup(docxml)
|
13
25
|
footnote_cleanup(docxml)
|
@@ -20,6 +32,7 @@ module IsoDoc::Function
|
|
20
32
|
end
|
21
33
|
|
22
34
|
def table_long_strings_cleanup(docxml)
|
35
|
+
return unless @break_up_urls_in_tables == true
|
23
36
|
docxml.xpath("//td | //th").each do |d|
|
24
37
|
d.traverse do |n|
|
25
38
|
next unless n.text?
|
@@ -30,6 +43,7 @@ module IsoDoc::Function
|
|
30
43
|
end
|
31
44
|
|
32
45
|
def break_up_long_strings(t)
|
46
|
+
return t if t.match(/^\s*$/)
|
33
47
|
t.split(/(?=\s)/).map do |w|
|
34
48
|
(/^\s*$/.match(t) or w.size < 30) ? w :
|
35
49
|
w.scan(/.{,30}/).map do |w1|
|
@@ -116,7 +130,7 @@ module IsoDoc::Function
|
|
116
130
|
end
|
117
131
|
|
118
132
|
def footnote_cleanup(docxml)
|
119
|
-
docxml.xpath('//a[@
|
133
|
+
docxml.xpath('//a[@class = "FootnoteRef"]/sup').each_with_index do |x, i|
|
120
134
|
x.content = (i + 1).to_s
|
121
135
|
end
|
122
136
|
docxml
|
data/lib/isodoc/function/i18n.rb
CHANGED
@@ -87,6 +87,7 @@ module IsoDoc::Function
|
|
87
87
|
|
88
88
|
# TODO: move to localization file
|
89
89
|
def eref_localities1(target, type, from, to, delim, lang = "en")
|
90
|
+
return "" if type == "anchor"
|
90
91
|
return l10n(eref_localities1_zh(target, type, from, to, delim)) if lang == "zh"
|
91
92
|
ret = delim
|
92
93
|
loc = @locality[type] || type.sub(/^locality:/, "").capitalize
|
@@ -1,28 +1,7 @@
|
|
1
|
+
require_relative "inline_simple"
|
2
|
+
|
1
3
|
module IsoDoc::Function
|
2
4
|
module Inline
|
3
|
-
def section_break(body)
|
4
|
-
body.br
|
5
|
-
end
|
6
|
-
|
7
|
-
def page_break(out)
|
8
|
-
out.br
|
9
|
-
end
|
10
|
-
|
11
|
-
def pagebreak_parse(_node, out)
|
12
|
-
out.br
|
13
|
-
end
|
14
|
-
|
15
|
-
def hr_parse(node, out)
|
16
|
-
out.hr
|
17
|
-
end
|
18
|
-
|
19
|
-
def br_parse(node, out)
|
20
|
-
out.br
|
21
|
-
end
|
22
|
-
|
23
|
-
def index_parse(node, out)
|
24
|
-
end
|
25
|
-
|
26
5
|
def link_parse(node, out)
|
27
6
|
out.a **attr_code(href: node["target"], title: node["alt"]) do |l|
|
28
7
|
if node.text.empty?
|
@@ -50,17 +29,39 @@ module IsoDoc::Function
|
|
50
29
|
(container && get_note_container_id(node) != container &&
|
51
30
|
@anchors[node["target"]]) &&
|
52
31
|
linkend = prefix_container(container, linkend, node["target"])
|
32
|
+
linkend = capitalise_xref(node, linkend)
|
53
33
|
end
|
54
34
|
linkend || "???"
|
55
35
|
end
|
56
36
|
|
37
|
+
def capitalise_xref(node, linkend)
|
38
|
+
return linkend unless %w(Latn Cyrl Grek).include? @script
|
39
|
+
return linkend&.capitalize if node["case"] == "capital"
|
40
|
+
return linkend&.downcase if node["case"] == "lowercase"
|
41
|
+
return linkend if linkend[0,1].match(/\p{Upper}/)
|
42
|
+
prec = nearest_block_parent(node).xpath("./descendant-or-self::text()") &
|
43
|
+
node.xpath("./preceding::text()")
|
44
|
+
(prec.empty? || /(?!<[^.].)\.\s+$/.match(prec.map { |p| p.text }.join)) ?
|
45
|
+
linkend&.capitalize : linkend
|
46
|
+
end
|
47
|
+
|
48
|
+
def nearest_block_parent(node)
|
49
|
+
until %w(p title td th name formula
|
50
|
+
li dt dd sourcecode pre).include?(node.name)
|
51
|
+
node = node.parent
|
52
|
+
end
|
53
|
+
node
|
54
|
+
end
|
55
|
+
|
57
56
|
def get_linkend(node)
|
58
|
-
contents = node.children.select
|
59
|
-
|
57
|
+
contents = node.children.select do |c|
|
58
|
+
!%w{locality localityStack}.include? c.name
|
59
|
+
end.select { |c| !c.text? || /\S/.match(c) }
|
60
60
|
!contents.empty? and
|
61
61
|
return Nokogiri::XML::NodeSet.new(node.document, contents).to_xml
|
62
62
|
link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
|
63
|
-
link + eref_localities(node.xpath(ns("./locality | ./localityStack")),
|
63
|
+
link + eref_localities(node.xpath(ns("./locality | ./localityStack")),
|
64
|
+
link)
|
64
65
|
# so not <origin bibitemid="ISO7301" citeas="ISO 7301">
|
65
66
|
# <locality type="section"><reference>3.1</reference></locality></origin>
|
66
67
|
end
|
@@ -83,27 +84,52 @@ module IsoDoc::Function
|
|
83
84
|
end
|
84
85
|
else
|
85
86
|
ret += eref_localities0(r, i, target, delim)
|
86
|
-
|
87
|
+
end
|
87
88
|
end
|
88
89
|
ret
|
89
90
|
end
|
90
91
|
|
91
92
|
def eref_localities0(r, i, target, delim)
|
92
|
-
if r["type"] == "whole" then l10n("#{delim} #{@
|
93
|
+
if r["type"] == "whole" then l10n("#{delim} #{@wholeoftext_lbl}")
|
93
94
|
else
|
94
95
|
eref_localities1(target, r["type"], r.at(ns("./referenceFrom")),
|
95
96
|
r.at(ns("./referenceTo")), delim, @lang)
|
96
97
|
end
|
97
98
|
end
|
98
99
|
|
100
|
+
def suffix_url(url)
|
101
|
+
return url if %r{^http[s]?://}.match(url)
|
102
|
+
url.sub(/#{File.extname(url)}$/, ".html")
|
103
|
+
end
|
104
|
+
|
105
|
+
def eref_target(node)
|
106
|
+
href = "#" + node["bibitemid"]
|
107
|
+
url = node.at(ns("//bibitem[@id = '#{node['bibitemid']}']/"\
|
108
|
+
"uri[@type = 'citation']"))
|
109
|
+
return href unless url
|
110
|
+
href = suffix_url(url.text)
|
111
|
+
anchor = node&.at(ns(".//locality[@type = 'anchor']"))&.text
|
112
|
+
anchor and href += "##{anchor}"
|
113
|
+
href
|
114
|
+
end
|
115
|
+
|
99
116
|
def eref_parse(node, out)
|
100
117
|
linkend = get_linkend(node)
|
118
|
+
href = eref_target(node)
|
101
119
|
if node["type"] == "footnote"
|
102
120
|
out.sup do |s|
|
103
|
-
s.a(**{ "href":
|
121
|
+
s.a(**{ "href": href }) { |l| l << linkend }
|
104
122
|
end
|
105
123
|
else
|
106
|
-
out.a(**{ "href":
|
124
|
+
out.a(**{ "href": href }) { |l| l << linkend }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def origin_parse(node, out)
|
129
|
+
if t = node.at(ns("./termref"))
|
130
|
+
termrefelem_parse(t, out)
|
131
|
+
else
|
132
|
+
eref_parse(node, out)
|
107
133
|
end
|
108
134
|
end
|
109
135
|
|
@@ -112,8 +138,9 @@ module IsoDoc::Function
|
|
112
138
|
end
|
113
139
|
|
114
140
|
def concept_parse(node, out)
|
115
|
-
content = node.first_element_child.children.select
|
116
|
-
|
141
|
+
content = node.first_element_child.children.select do |c|
|
142
|
+
!%w{locality localityStack}.include? c.name
|
143
|
+
end.select { |c| !c.text? || /\S/.match(c) }
|
117
144
|
if content.empty?
|
118
145
|
out << "[Term defined in "
|
119
146
|
parse(node.first_element_child, out)
|
@@ -125,7 +152,8 @@ module IsoDoc::Function
|
|
125
152
|
|
126
153
|
def stem_parse(node, out)
|
127
154
|
ooml = if node["type"] == "AsciiMath"
|
128
|
-
"#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}
|
155
|
+
"#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}"\
|
156
|
+
"#{@closemathdelim}"
|
129
157
|
elsif node["type"] == "MathML" then node.first_element_child.to_s
|
130
158
|
else
|
131
159
|
HTMLEntities.new.encode(node.text)
|
@@ -167,57 +195,31 @@ module IsoDoc::Function
|
|
167
195
|
out << text
|
168
196
|
end
|
169
197
|
|
170
|
-
def
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
def keyword_parse(node, out)
|
175
|
-
out.span **{ class: "keyword" } do |s|
|
176
|
-
node.children.each { |n| parse(n, s) }
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
def em_parse(node, out)
|
181
|
-
out.i do |e|
|
182
|
-
node.children.each { |n| parse(n, e) }
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
def strong_parse(node, out)
|
187
|
-
out.b do |e|
|
188
|
-
node.children.each { |n| parse(n, e) }
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
def sup_parse(node, out)
|
193
|
-
out.sup do |e|
|
194
|
-
node.children.each { |n| parse(n, e) }
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
def sub_parse(node, out)
|
199
|
-
out.sub do |e|
|
200
|
-
node.children.each { |n| parse(n, e) }
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def tt_parse(node, out)
|
205
|
-
out.tt do |e|
|
206
|
-
node.children.each { |n| parse(n, e) }
|
198
|
+
def error_parse(node, out)
|
199
|
+
text = node.to_xml.gsub(/</, "<").gsub(/>/, ">")
|
200
|
+
out.para do |p|
|
201
|
+
p.b(**{ role: "strong" }) { |e| e << text }
|
207
202
|
end
|
208
203
|
end
|
209
204
|
|
210
|
-
def
|
211
|
-
|
212
|
-
node.children.each { |n| parse(n,
|
205
|
+
def variant_parse(node, out)
|
206
|
+
if node["lang"] == @lang && node["script"] == @script
|
207
|
+
node.children.each { |n| parse(n, out) }
|
208
|
+
else
|
209
|
+
return if found_matching_variant_sibling(node)
|
210
|
+
return unless !node.at("./preceding-sibling::xmlns:variant")
|
211
|
+
node.children.each { |n| parse(n, out) }
|
213
212
|
end
|
214
213
|
end
|
215
214
|
|
216
|
-
def
|
217
|
-
|
218
|
-
|
219
|
-
|
215
|
+
def found_matching_variant_sibling(node)
|
216
|
+
prev = node.xpath("./preceding-sibling::xmlns:variant")
|
217
|
+
foll = node.xpath("./following-sibling::xmlns:variant")
|
218
|
+
found = false
|
219
|
+
(prev + foll).each do |n|
|
220
|
+
found = true if n["lang"] == @lang && n["script"] == @script
|
220
221
|
end
|
222
|
+
found
|
221
223
|
end
|
222
224
|
end
|
223
225
|
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module IsoDoc::Function
|
2
|
+
module Inline
|
3
|
+
def section_break(body)
|
4
|
+
body.br
|
5
|
+
end
|
6
|
+
|
7
|
+
def page_break(out)
|
8
|
+
out.br
|
9
|
+
end
|
10
|
+
|
11
|
+
def pagebreak_parse(_node, out)
|
12
|
+
out.br
|
13
|
+
end
|
14
|
+
|
15
|
+
def hr_parse(node, out)
|
16
|
+
out.hr
|
17
|
+
end
|
18
|
+
|
19
|
+
def br_parse(node, out)
|
20
|
+
out.br
|
21
|
+
end
|
22
|
+
|
23
|
+
def index_parse(node, out)
|
24
|
+
end
|
25
|
+
|
26
|
+
def bookmark_parse(node, out)
|
27
|
+
out.a **attr_code(id: node["id"])
|
28
|
+
end
|
29
|
+
|
30
|
+
def keyword_parse(node, out)
|
31
|
+
out.span **{ class: "keyword" } do |s|
|
32
|
+
node.children.each { |n| parse(n, s) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def em_parse(node, out)
|
37
|
+
out.i do |e|
|
38
|
+
node.children.each { |n| parse(n, e) }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def strong_parse(node, out)
|
43
|
+
out.b do |e|
|
44
|
+
node.children.each { |n| parse(n, e) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def sup_parse(node, out)
|
49
|
+
out.sup do |e|
|
50
|
+
node.children.each { |n| parse(n, e) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def sub_parse(node, out)
|
55
|
+
out.sub do |e|
|
56
|
+
node.children.each { |n| parse(n, e) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def tt_parse(node, out)
|
61
|
+
out.tt do |e|
|
62
|
+
node.children.each { |n| parse(n, e) }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def strike_parse(node, out)
|
67
|
+
out.s do |e|
|
68
|
+
node.children.each { |n| parse(n, e) }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
module IsoDoc::Function
|
2
2
|
module Lists
|
3
|
+
def ul_attrs(node)
|
4
|
+
{ id: node["id"], style: keep_style(node) }
|
5
|
+
end
|
3
6
|
|
4
7
|
def ul_parse(node, out)
|
5
|
-
out.ul **attr_code(
|
8
|
+
out.ul **attr_code(ul_attrs(node)) do |ul|
|
6
9
|
node.children.each { |n| parse(n, ul) }
|
7
10
|
end
|
8
11
|
end
|
@@ -34,9 +37,12 @@ module IsoDoc::Function
|
|
34
37
|
ol_style(type)
|
35
38
|
end
|
36
39
|
|
40
|
+
def ol_attrs(node)
|
41
|
+
{ type: ol_depth(node), id: node["id"], style: keep_style(node) }
|
42
|
+
end
|
43
|
+
|
37
44
|
def ol_parse(node, out)
|
38
|
-
|
39
|
-
out.ol **attr_code(type: style, id: node["id"] ) do |ol|
|
45
|
+
out.ol **attr_code(ol_attrs(node)) do |ol|
|
40
46
|
node.children.each { |n| parse(n, ol) }
|
41
47
|
end
|
42
48
|
end
|
@@ -67,12 +73,12 @@ module IsoDoc::Function
|
|
67
73
|
%w{dt dd}.include? n.name
|
68
74
|
end
|
69
75
|
|
70
|
-
def
|
71
|
-
attr_code(id: node["id"])
|
76
|
+
def dl_attrs(node)
|
77
|
+
attr_code(id: node["id"], style: keep_style(node))
|
72
78
|
end
|
73
79
|
|
74
80
|
def dl_parse(node, out)
|
75
|
-
out.dl **
|
81
|
+
out.dl **dl_attrs(node) do |v|
|
76
82
|
node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
|
77
83
|
v.dt **attr_code(id: dt["id"]) do |term|
|
78
84
|
dt_parse(dt, term)
|
@@ -5,30 +5,31 @@ module IsoDoc::Function
|
|
5
5
|
# references anyway; keeping here instead of in IsoDoc::Iso for now
|
6
6
|
def docid_l10n(x)
|
7
7
|
return x if x.nil?
|
8
|
-
x.gsub(/All Parts/i, @all_parts_lbl.downcase)
|
8
|
+
x.gsub(/All Parts/i, @all_parts_lbl.downcase) if @all_parts_lbl
|
9
|
+
x
|
9
10
|
end
|
10
11
|
|
11
12
|
# TODO generate formatted ref if not present
|
12
|
-
def nonstd_bibitem(list, b, ordinal,
|
13
|
-
list.p **attr_code(iso_bibitem_entry_attrs(b,
|
14
|
-
|
15
|
-
|
16
|
-
if
|
13
|
+
def nonstd_bibitem(list, b, ordinal, biblio)
|
14
|
+
list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
|
15
|
+
ids = bibitem_ref_code(b)
|
16
|
+
identifiers = render_identifier(ids)
|
17
|
+
if biblio then ref_entry_code(ref, ordinal, identifiers, ids)
|
17
18
|
else
|
18
|
-
|
19
|
-
|
19
|
+
ref << "#{identifiers[0] || identifiers[1]}, "
|
20
|
+
ref << "#{identifiers[1]}, " if identifiers[0] && identifiers[1]
|
20
21
|
end
|
21
|
-
reference_format(b,
|
22
|
+
reference_format(b, ref)
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
26
|
def std_bibitem_entry(list, b, ordinal, biblio)
|
26
27
|
list.p **attr_code(iso_bibitem_entry_attrs(b, biblio)) do |ref|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
ref <<
|
28
|
+
ids = bibitem_ref_code(b)
|
29
|
+
identifiers = render_identifier(ids)
|
30
|
+
prefix_bracketed_ref(ref, "[#{ordinal}]") if biblio
|
31
|
+
ref << "#{identifiers[0] || identifiers[1]}"
|
32
|
+
ref << ", #{identifiers[1]}" if identifiers[0] && identifiers[1]
|
32
33
|
date_note_process(b, ref)
|
33
34
|
ref << ", "
|
34
35
|
reference_format(b, ref)
|
@@ -38,29 +39,43 @@ module IsoDoc::Function
|
|
38
39
|
# if t is just a number, only use that ([1] Non-Standard)
|
39
40
|
# else, use both ordinal, as prefix, and t
|
40
41
|
def ref_entry_code(r, ordinal, t, id)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
prefix_bracketed_ref(r, ordinal)
|
45
|
-
if !t.empty? && !%w(DOI ISSN ISBN).include?(id["type"])
|
46
|
-
r << "#{t}, "
|
47
|
-
end
|
42
|
+
prefix_bracketed_ref(r, t[0] || "[#{ordinal}]")
|
43
|
+
if t[1]
|
44
|
+
r << "#{t[1]}, "
|
48
45
|
end
|
49
46
|
end
|
50
47
|
|
48
|
+
def pref_ref_code(b)
|
49
|
+
b.at(ns("./docidentifier[not(@type = 'DOI' or @type = 'metanorma' "\
|
50
|
+
"or @type = 'ISSN' or @type = 'ISBN' or @type = 'rfc-anchor')]"))
|
51
|
+
end
|
52
|
+
|
53
|
+
# returns [metanorma, non-metanorma, DOI/ISSN/ISBN] identifiers
|
51
54
|
def bibitem_ref_code(b)
|
52
55
|
id = b.at(ns("./docidentifier[@type = 'metanorma']"))
|
53
|
-
|
54
|
-
|
55
|
-
id
|
56
|
-
return id if id
|
56
|
+
id1 = pref_ref_code(b)
|
57
|
+
id2 = b.at(ns("./docidentifier[@type = 'DOI' or @type = 'ISSN' or @type = 'ISBN']"))
|
58
|
+
return [id, id1, id2] if id || id1 || id2
|
57
59
|
id = Nokogiri::XML::Node.new("docidentifier", b.document)
|
58
60
|
id << "(NO ID)"
|
59
|
-
id
|
61
|
+
[nil, id, nil]
|
62
|
+
end
|
63
|
+
|
64
|
+
def bracket_if_num(x)
|
65
|
+
return nil if x.nil?
|
66
|
+
x = x.text.sub(/^\[/, "").sub(/\]$/, "")
|
67
|
+
return "[#{x}]" if /^\d+$/.match(x)
|
68
|
+
x
|
60
69
|
end
|
61
70
|
|
62
71
|
def render_identifier(id)
|
63
|
-
|
72
|
+
[
|
73
|
+
bracket_if_num(id[0]),
|
74
|
+
id[1].nil? ? nil :
|
75
|
+
docid_prefix(id[1]["type"], id[1].text.sub(/^\[/, "").sub(/\]$/, "")),
|
76
|
+
id[2].nil? ? nil :
|
77
|
+
docid_prefix(id[2]["type"], id[2].text.sub(/^\[/, "").sub(/\]$/, "")),
|
78
|
+
]
|
64
79
|
end
|
65
80
|
|
66
81
|
def docid_prefix(prefix, docid)
|
@@ -70,13 +85,12 @@ module IsoDoc::Function
|
|
70
85
|
|
71
86
|
def omit_docid_prefix(prefix)
|
72
87
|
return true if prefix.nil? || prefix.empty?
|
73
|
-
return %w(ISO IEC ITU metanorma).include? prefix
|
88
|
+
return %w(ISO IEC ITU W3C metanorma).include? prefix
|
74
89
|
end
|
75
90
|
|
76
91
|
def date_note_process(b, ref)
|
77
|
-
date_note = b.at(ns("./note[
|
92
|
+
date_note = b.at(ns("./note[@type = 'ISO DATE']"))
|
78
93
|
return if date_note.nil?
|
79
|
-
date_note.content = date_note.content.gsub(/ISO DATE: /, "")
|
80
94
|
date_note.children.first.replace("<p>#{date_note.content}</p>")
|
81
95
|
footnote_parse(date_note, ref)
|
82
96
|
end
|
@@ -100,7 +114,7 @@ module IsoDoc::Function
|
|
100
114
|
end
|
101
115
|
|
102
116
|
def prefix_bracketed_ref(ref, text)
|
103
|
-
ref <<
|
117
|
+
ref << text.to_s
|
104
118
|
insert_tab(ref, 1)
|
105
119
|
end
|
106
120
|
|
@@ -146,8 +160,7 @@ module IsoDoc::Function
|
|
146
160
|
end
|
147
161
|
|
148
162
|
def norm_ref(isoxml, out, num)
|
149
|
-
q = "//bibliography/references[
|
150
|
-
"title = 'Normative references']"
|
163
|
+
q = "//bibliography/references[@normative = 'true']"
|
151
164
|
f = isoxml.at(ns(q)) or return num
|
152
165
|
out.div do |div|
|
153
166
|
num = num + 1
|
@@ -157,8 +170,8 @@ module IsoDoc::Function
|
|
157
170
|
num
|
158
171
|
end
|
159
172
|
|
160
|
-
BIBLIOGRAPHY_XPATH = "//bibliography/clause[
|
161
|
-
"//bibliography/references[
|
173
|
+
BIBLIOGRAPHY_XPATH = "//bibliography/clause[.//references[@normative = 'false']] | "\
|
174
|
+
"//bibliography/references[@normative = 'false']".freeze
|
162
175
|
|
163
176
|
def bibliography(isoxml, out)
|
164
177
|
f = isoxml.at(ns(BIBLIOGRAPHY_XPATH)) || return
|
@@ -188,12 +201,11 @@ module IsoDoc::Function
|
|
188
201
|
|
189
202
|
def reference_names(ref)
|
190
203
|
isopub = ref.at(ns(ISO_PUBLISHER_XPATH))
|
191
|
-
|
192
|
-
|
204
|
+
ids = bibitem_ref_code(ref)
|
205
|
+
identifiers = render_identifier(ids)
|
193
206
|
date = ref.at(ns("./date[@type = 'published']"))
|
194
207
|
allparts = ref.at(ns("./extent[@type='part'][referenceFrom='all']"))
|
195
|
-
reference =
|
196
|
-
allparts)
|
208
|
+
reference = docid_l10n(identifiers[0] || identifiers[1])
|
197
209
|
@anchors[ref["id"]] = { xref: reference }
|
198
210
|
end
|
199
211
|
|