metanorma-standoc 1.9.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,7 +21,7 @@ module Asciidoctor
21
21
  end
22
22
  end
23
23
 
24
- def organization(org, orgname, node = nil, default_org = nil)
24
+ def organization(org, orgname, is_pub, node = nil, default_org = nil)
25
25
  abbrevs = org_abbrev
26
26
  n = abbrevs.invert[orgname] and orgname = n
27
27
  org.name orgname
@@ -29,7 +29,7 @@ module Asciidoctor
29
29
  abbr = org_abbrev[orgname]
30
30
  default_org && b = node.attr("subdivision-abbr") and abbr = b
31
31
  abbr and org.abbreviation abbr
32
- default_org and org_address(node, org)
32
+ is_pub && node and org_address(node, org)
33
33
  end
34
34
 
35
35
  def org_address(node, p)
@@ -59,7 +59,7 @@ module Asciidoctor
59
59
  xml.contributor do |c|
60
60
  c.role **{ type: "author" }
61
61
  c.organization do |a|
62
- organization(a, p, node, !node.attr("publisher"))
62
+ organization(a, p, false, node, !node.attr("publisher"))
63
63
  end
64
64
  end
65
65
  end
@@ -144,7 +144,7 @@ module Asciidoctor
144
144
  xml.contributor do |c|
145
145
  c.role **{ type: "publisher" }
146
146
  c.organization do |a|
147
- organization(a, p, node, !node.attr("publisher"))
147
+ organization(a, p, true, node, !node.attr("publisher"))
148
148
  end
149
149
  end
150
150
  end
@@ -157,7 +157,7 @@ module Asciidoctor
157
157
  c.from (node.attr("copyright-year") || Date.today.year)
158
158
  p.match(/[A-Za-z]/).nil? or c.owner do |owner|
159
159
  owner.organization do |a|
160
- organization(a, p, node, !pub)
160
+ organization(a, p, true, node, !pub)
161
161
  end
162
162
  end
163
163
  end
@@ -28,14 +28,16 @@ module Asciidoctor
28
28
  end
29
29
 
30
30
  def ul_li_attrs(node)
31
+ c = node.attr?("checked")
31
32
  attr_code(
32
- uncheckedcheckbox: node.attr?("checkbox") ? !node.attr?("checked") : nil,
33
- checkedcheckbox: node.attr?("checkbox") ? node.attr?("checked") : nil,
33
+ uncheckedcheckbox: node.attr?("checkbox") ? !c : nil,
34
+ checkedcheckbox: node.attr?("checkbox") ? c : nil
34
35
  )
35
36
  end
36
37
 
37
38
  def ulist(node)
38
39
  return reference(node) if in_norm_ref? || in_biblio?
40
+
39
41
  noko do |xml|
40
42
  xml.ul **ul_attrs(node) do |xml_ul|
41
43
  node.items.each do |item|
@@ -1,12 +1,14 @@
1
+ require_relative "ref_date_id"
2
+
1
3
  module Asciidoctor
2
4
  module Standoc
3
5
  module Refs
4
- def iso_publisher(t, code)
6
+ def iso_publisher(bib, code)
5
7
  code.sub(/ .*$/, "").split(/\//).each do |abbrev|
6
- t.contributor do |c|
8
+ bib.contributor do |c|
7
9
  c.role **{ type: "publisher" }
8
10
  c.organization do |org|
9
- organization(org, abbrev)
11
+ organization(org, abbrev, true)
10
12
  end
11
13
  end
12
14
  end
@@ -20,58 +22,19 @@ module Asciidoctor
20
22
  { id: m[:anchor], type: "standard" }
21
23
  end
22
24
 
23
- def set_date_range(date, text)
24
- matched = /^(?<from>[0-9]+)(-+(?<to>[0-9]+))?$/.match text
25
- return unless matched[:from]
26
- if matched[:to]
27
- date.from matched[:from]
28
- date.to matched[:to]
29
- else
30
- date.on matched[:from]
31
- end
32
- end
33
-
34
- def use_my_anchor(ref, id)
35
- ref.parent.elements.last["id"] = id
36
- ref
37
- end
38
-
39
- def id_and_year(id, year)
40
- year ? "#{id}:#{year}" : id
41
- end
42
-
43
- def docid(t, code)
44
- type, code1 = /^\[\d+\]$|^\([^)]+\).*$/.match(code) ?
45
- ["metanorma", mn_code(code)] : @bibdb&.docid_type(code) || [nil, code]
46
- code1.sub!(/^nofetch\((.+)\)$/, "\\1")
47
- t.docidentifier **attr_code(type: type) do |d|
48
- d << code1
49
- end
50
- end
51
-
52
- def docnumber(t, code)
53
- t.docnumber do |d|
54
- d << HTMLEntities.new.decode(code).sub(/^[^\d]*/, "")
55
- end
56
- end
57
-
58
- def norm_year(yr)
59
- /^\&\#821[12];$/.match(yr) and return "--"
60
- /^\d\d\d\d-\d\d\d\d$/.match(yr) and return yr
61
- yr&.sub(/(?<=[0-9])-.*$/, "")
62
- end
63
-
64
- def isorefrender1(t, m, yr, allp = "")
65
- t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
66
- docid(t, m[:usrlbl]) if m[:usrlbl]
67
- docid(t, id_and_year(m[:code], yr) + allp)
68
- docnumber(t, m[:code])
25
+ def isorefrender1(bib, m, yr, allp = "")
26
+ bib.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
27
+ docid(bib, m[:usrlbl]) if m[:usrlbl]
28
+ docid(bib, id_and_year(m[:code], yr) + allp)
29
+ docnumber(bib, m[:code])
69
30
  end
70
31
 
71
32
  def isorefmatches(xml, m)
72
33
  yr = norm_year(m[:year])
73
- ref = fetch_ref xml, m[:code], yr, title: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
34
+ ref = fetch_ref xml, m[:code], yr, title: m[:text], usrlbl: m[:usrlbl],
35
+ lang: (@lang || :all)
74
36
  return use_my_anchor(ref, m[:anchor]) if ref
37
+
75
38
  xml.bibitem **attr_code(ref_attributes(m)) do |t|
76
39
  isorefrender1(t, m, yr)
77
40
  yr and t.date **{ type: "published" } do |d|
@@ -85,6 +48,7 @@ module Asciidoctor
85
48
  ref = fetch_ref xml, m[:code], nil, no_year: true, note: m[:fn],
86
49
  title: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
87
50
  return use_my_anchor(ref, m[:anchor]) if ref
51
+
88
52
  isorefmatches2_1(xml, m)
89
53
  end
90
54
 
@@ -95,49 +59,51 @@ module Asciidoctor
95
59
  d.on "--"
96
60
  end
97
61
  iso_publisher(t, m[:code])
98
- m[:fn].nil? or t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
99
- p << "#{m[:fn]}"
62
+ unless m[:fn].nil?
63
+ t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
64
+ p << (m[:fn]).to_s
65
+ end
100
66
  end
101
67
  end
102
68
  end
103
69
 
104
- def conditional_date(t, m, noyr)
105
- m.names.include?("year") and !m[:year].nil? and
106
- t.date(**{ type: "published" }) do |d|
107
- noyr and d.on "--" or set_date_range(d, norm_year(m[:year]))
108
- end
109
- end
110
-
111
70
  def isorefmatches3(xml, m)
112
71
  yr = norm_year(m[:year])
113
72
  hasyr = !yr.nil? && yr != "--"
114
- ref = fetch_ref xml, m[:code], hasyr ? yr : nil, all_parts: true,
115
- no_year: yr == "--", text: m[:text], usrlbl: m[:usrlbl], lang: (@lang || :all)
73
+ ref = fetch_ref(xml, m[:code], hasyr ? yr : nil,
74
+ all_parts: true,
75
+ no_year: yr == "--", text: m[:text], usrlbl: m[:usrlbl],
76
+ lang: (@lang || :all))
116
77
  return use_my_anchor(ref, m[:anchor]) if ref
78
+
117
79
  isorefmatches3_1(xml, m, yr, hasyr, ref)
118
80
  end
119
81
 
120
- def isorefmatches3_1(xml, m, yr, hasyr, ref)
82
+ def isorefmatches3_1(xml, m, yr, _hasyr, _ref)
121
83
  xml.bibitem(**attr_code(ref_attributes(m))) do |t|
122
84
  isorefrender1(t, m, yr, " (all parts)")
123
85
  conditional_date(t, m, yr == "--")
124
86
  iso_publisher(t, m[:code])
125
- m.names.include?("fn") && m[:fn] and
126
- t.note(**plaintxt.merge(type: "Unpublished-Status")) { |p| p << "#{m[:fn]}" }
127
- t.extent **{ type: 'part' } do |e|
87
+ if m.names.include?("fn") && m[:fn]
88
+ t.note(**plaintxt.merge(type: "Unpublished-Status")) do |p|
89
+ p << (m[:fn]).to_s
90
+ end
91
+ end
92
+ t.extent **{ type: "part" } do |e|
128
93
  e.referenceFrom "all"
129
94
  end
130
95
  end
131
96
  end
132
97
 
133
- def refitem_render1(m, code, t)
98
+ def refitem_render1(m, code, bib)
134
99
  if code[:type] == "path"
135
- t.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "URI" }
136
- t.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "citation" }
100
+ bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "URI" }
101
+ bib.uri code[:key].sub(/\.[a-zA-Z0-9]+$/, ""), **{ type: "citation" }
137
102
  end
138
- docid(t, m[:usrlbl]) if m[:usrlbl]
139
- docid(t, /^\d+$/.match(code[:id]) ? "[#{code[:id]}]" : code[:id])
140
- code[:type] == "repo" and t.docidentifier code[:key], **{ type: "repository" }
103
+ docid(bib, m[:usrlbl]) if m[:usrlbl]
104
+ docid(bib, /^\d+$/.match?(code[:id]) ? "[#{code[:id]}]" : code[:id])
105
+ code[:type] == "repo" and
106
+ bib.docidentifier code[:key], **{ type: "repository" }
141
107
  end
142
108
 
143
109
  def refitem_render(xml, m, code)
@@ -146,7 +112,7 @@ module Asciidoctor
146
112
  i << ref_normalise_no_format(m[:text])
147
113
  end
148
114
  refitem_render1(m, code, t)
149
- docnumber(t, code[:id]) unless /^\d+$|^\(.+\)$/.match(code[:id])
115
+ docnumber(t, code[:id]) unless /^\d+$|^\(.+\)$/.match?(code[:id])
150
116
  end
151
117
  end
152
118
 
@@ -156,25 +122,30 @@ module Asciidoctor
156
122
 
157
123
  def analyse_ref_nofetch(ret)
158
124
  return ret unless m = /^nofetch\((?<id>.+)\)$/.match(ret[:id])
125
+
159
126
  ret.merge(id: m[:id], nofetch: true)
160
127
  end
161
128
 
162
129
  def analyse_ref_repo_path(ret)
163
- return ret unless m = /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
130
+ return ret unless m =
131
+ /^(?<type>repo|path):\((?<key>[^,]+),?(?<id>.*)\)$/.match(ret[:id])
132
+
164
133
  id = m[:id].empty? ? m[:key].sub(%r{^[^/]+/}, "") : m[:id]
165
134
  ret.merge(id: id, type: m[:type], key: m[:key], nofetch: true)
166
135
  end
167
136
 
168
137
  def analyse_ref_numeric(ret)
169
- return ret unless /^\d+$/.match(ret[:id])
138
+ return ret unless /^\d+$/.match?(ret[:id])
139
+
170
140
  ret.merge(numeric: true)
171
141
  end
172
142
 
173
143
  # ref id = (usrlbl)code[:-]year
174
144
  # code = nofetch(code) | (repo|path):(key,code) | \[? number \]? | ident
175
145
  def analyse_ref_code(code)
176
- ret = {id: code}
177
- return ret if code.nil? || code.empty?
146
+ ret = { id: code }
147
+ return ret if code.blank?
148
+
178
149
  analyse_ref_nofetch(analyse_ref_repo_path(analyse_ref_numeric(ret)))
179
150
  end
180
151
 
@@ -185,11 +156,13 @@ module Asciidoctor
185
156
  nil
186
157
  end
187
158
 
188
- def refitem1(xml, item, m)
159
+ def refitem1(xml, _item, m)
189
160
  code = analyse_ref_code(m[:code])
190
161
  unless code[:id] && code[:numeric] || code[:nofetch]
191
- ref = fetch_ref xml, code[:id], m.names.include?("year") ? m[:year] : nil, title: m[:text],
192
- usrlbl: m[:usrlbl], lang: (@lang || :all)
162
+ ref = fetch_ref(xml, code[:id],
163
+ m.names.include?("year") ? m[:year] : nil,
164
+ title: m[:text],
165
+ usrlbl: m[:usrlbl], lang: (@lang || :all))
193
166
  return use_my_anchor(ref, m[:anchor]) if ref
194
167
  end
195
168
  refitem_render(xml, m, code)
@@ -203,44 +176,46 @@ module Asciidoctor
203
176
  ref.gsub(/&amp;amp;/, "&amp;")
204
177
  end
205
178
 
206
- ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
179
+ ISO_REF =
180
+ %r{^<ref\sid="(?<anchor>[^"]+)">
207
181
  \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
208
- (:(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm
182
+ (:(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm.freeze
209
183
 
210
- ISO_REF_NO_YEAR = %r{^<ref\sid="(?<anchor>[^"]+)">
184
+ ISO_REF_NO_YEAR =
185
+ %r{^<ref\sid="(?<anchor>[^"]+)">
211
186
  \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):
212
- (--|\&\#821[12]\;)\]</ref>,?\s*
187
+ (--|&\#821[12];)\]</ref>,?\s*
213
188
  (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
214
-
215
- ISO_REF_ALL_PARTS = %r{^<ref\sid="(?<anchor>[^"]+)">
216
- \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)
217
- (:(?<year>--|\&\#821[12]\;|[0-9][0-9-]+))?\s
218
- \(all\sparts\)\]</ref>,?\s*
219
- (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm
220
-
221
- NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
222
- \[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)
223
- ([:-](?<year>(19|20)[0-9][0-9][0-9-]*))?\]</ref>,?\s*(?<text>.*)$}xm
224
-
225
- def reference1_matches(item)
226
- matched = ISO_REF.match item
227
- matched2 = ISO_REF_NO_YEAR.match item
228
- matched3 = ISO_REF_ALL_PARTS.match item
229
- [matched, matched2, matched3]
230
- end
231
-
232
- def reference1(node, item, xml)
233
- matched, matched2, matched3 = reference1_matches(item)
234
- if matched3.nil? && matched2.nil? && matched.nil? then refitem(xml, item, node)
235
- elsif !matched.nil? then isorefmatches(xml, matched)
236
- elsif !matched2.nil? then isorefmatches2(xml, matched2)
237
- elsif !matched3.nil? then isorefmatches3(xml, matched3)
238
- end
239
- end
240
-
241
- def mn_code(code)
242
- code.sub(/^\(/, "[").sub(/\).*$/, "]").sub(/^nofetch\((.+)\)$/, "\\1")
189
+ .freeze
190
+
191
+ ISO_REF_ALL_PARTS =
192
+ %r{^<ref\sid="(?<anchor>[^"]+)">
193
+ \[(?<usrlbl>\([^)]+\))?(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)
194
+ (:(?<year>--|&\#821[12];|[0-9][0-9-]+))?\s
195
+ \(all\sparts\)\]</ref>,?\s*
196
+ (<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm.freeze
197
+
198
+ NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
199
+ \[(?<usrlbl>\([^)]+\))?(?<code>[^\]]+?)
200
+ ([:-](?<year>(19|20)[0-9][0-9][0-9-]*))?\]</ref>,?\s*(?<text>.*)$}xm
201
+ .freeze
202
+
203
+ def reference1_matches(item)
204
+ matched = ISO_REF.match item
205
+ matched2 = ISO_REF_NO_YEAR.match item
206
+ matched3 = ISO_REF_ALL_PARTS.match item
207
+ [matched, matched2, matched3]
208
+ end
209
+
210
+ def reference1(node, item, xml)
211
+ matched, matched2, matched3 = reference1_matches(item)
212
+ if matched3.nil? && matched2.nil? && matched.nil?
213
+ refitem(xml, item, node)
214
+ elsif !matched.nil? then isorefmatches(xml, matched)
215
+ elsif !matched2.nil? then isorefmatches2(xml, matched2)
216
+ elsif !matched3.nil? then isorefmatches3(xml, matched3)
243
217
  end
218
+ end
244
219
  end
245
220
  end
246
221
  end
@@ -0,0 +1,62 @@
1
+ module Asciidoctor
2
+ module Standoc
3
+ module Refs
4
+ def set_date_range(date, text)
5
+ matched = /^(?<from>[0-9]+)(-+(?<to>[0-9]+))?$/.match text
6
+ return unless matched[:from]
7
+
8
+ if matched[:to]
9
+ date.from matched[:from]
10
+ date.to matched[:to]
11
+ else
12
+ date.on matched[:from]
13
+ end
14
+ end
15
+
16
+ def id_and_year(id, year)
17
+ year ? "#{id}:#{year}" : id
18
+ end
19
+
20
+ def norm_year(year)
21
+ /^&\#821[12];$/.match(year) and return "--"
22
+ /^\d\d\d\d-\d\d\d\d$/.match(year) and return year
23
+ year&.sub(/(?<=[0-9])-.*$/, "")
24
+ end
25
+
26
+ def conditional_date(bib, match, noyr)
27
+ if match.names.include?("year") && !match[:year].nil?
28
+ bib.date(**{ type: "published" }) do |d|
29
+ noyr and d.on "--" or set_date_range(d, norm_year(match[:year]))
30
+ end
31
+ end
32
+ end
33
+
34
+ def use_my_anchor(ref, id)
35
+ ref.parent.elements.last["id"] = id
36
+ ref
37
+ end
38
+
39
+ def docid(bib, code)
40
+ type, code1 = if /^\[\d+\]$|^\([^)]+\).*$/.match?(code)
41
+ ["metanorma", mn_code(code)]
42
+ else
43
+ @bibdb&.docid_type(code) || [nil, code]
44
+ end
45
+ code1.sub!(/^nofetch\((.+)\)$/, "\\1")
46
+ bib.docidentifier **attr_code(type: type) do |d|
47
+ d << code1
48
+ end
49
+ end
50
+
51
+ def docnumber(bib, code)
52
+ bib.docnumber do |d|
53
+ d << HTMLEntities.new.decode(code).sub(/^[^\d]*/, "")
54
+ end
55
+ end
56
+
57
+ def mn_code(code)
58
+ code.sub(/^\(/, "[").sub(/\).*$/, "]").sub(/^nofetch\((.+)\)$/, "\\1")
59
+ end
60
+ end
61
+ end
62
+ end
@@ -19,11 +19,11 @@ module Asciidoctor
19
19
  end
20
20
 
21
21
  NOKOHEAD = <<~HERE.freeze
22
- <!DOCTYPE html SYSTEM
23
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
24
- <html xmlns="http://www.w3.org/1999/xhtml">
25
- <head> <title></title> <meta charset="UTF-8" /> </head>
26
- <body> </body> </html>
22
+ <!DOCTYPE html SYSTEM
23
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
24
+ <html xmlns="http://www.w3.org/1999/xhtml">
25
+ <head> <title></title> <meta charset="UTF-8" /> </head>
26
+ <body> </body> </html>
27
27
  HERE
28
28
 
29
29
  # block for processing XML document fragments as XHTML,
@@ -66,10 +66,36 @@ module Asciidoctor
66
66
  conv
67
67
  end
68
68
 
69
+ def default_script(lang)
70
+ case lang
71
+ when "ar", "fa"
72
+ "Arab"
73
+ when "ur"
74
+ "Aran"
75
+ when "ru", "bg"
76
+ "Cyrl"
77
+ when "hi"
78
+ "Deva"
79
+ when "el"
80
+ "Grek"
81
+ when "zh"
82
+ "Hans"
83
+ when "ko"
84
+ "Kore"
85
+ when "he"
86
+ "Hebr"
87
+ when "ja"
88
+ "Jpan"
89
+ else
90
+ "Latn"
91
+ end
92
+ end
93
+
69
94
  class EmptyAttr
70
- def attr(_x)
95
+ def attr(_any_attribute)
71
96
  nil
72
97
  end
98
+
73
99
  def attributes
74
100
  {}
75
101
  end