metanorma-jis 0.3.6 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,7 +54,7 @@ module IsoDoc
54
54
  isoxml.xpath(ns("//bibdata/date")).each do |d|
55
55
  val = Common::date_range(d)
56
56
  @lang == "ja" and val = @i18n.japanese_date(val)
57
- set("#{d['type'].gsub(/-/, '_')}date".to_sym, val)
57
+ set("#{d['type'].tr('-', '_')}date".to_sym, val)
58
58
  end
59
59
  end
60
60
 
@@ -65,7 +65,7 @@ module IsoDoc
65
65
  dest = doc.at(ns("//sections")) ||
66
66
  doc.at(ns("//preface")).after("<sections> </sections>").next_element
67
67
  dest.children.empty? and dest.children = " "
68
- dest.children.first.next = source
68
+ dest.add_first_child source
69
69
  end
70
70
 
71
71
  def move_participants(doc)
@@ -73,7 +73,7 @@ module IsoDoc
73
73
  t = participant_table(p) or return
74
74
  p.remove
75
75
  ins = make_preface(doc) or return nil
76
- ins.children.first.previous = t
76
+ ins.add_first_child t
77
77
  end
78
78
 
79
79
  def participant_table(clause)
@@ -45,12 +45,8 @@ module IsoDoc
45
45
  elem.children.first.previous = @i18n.l10n("#{@i18n.admitted}: ")
46
46
  end
47
47
 
48
- def block(docxml)
49
- super
50
- dl docxml
51
- end
52
-
53
48
  def dl(docxml)
49
+ super
54
50
  docxml.xpath(ns("//table//dl | //figure//dl")).each do |l|
55
51
  l.at(ns("./dl")) || l.at("./ancestor::xmlns:dl") and next
56
52
  dl_to_para(l)
@@ -135,6 +131,10 @@ module IsoDoc
135
131
  elem.children = l10n("#{@i18n.source}: #{to_xml(elem.children).strip}")
136
132
  end
137
133
 
134
+ def table_fn1(_table, fnote, _idx)
135
+ fnote["reference"] += ")"
136
+ end
137
+
138
138
  def bibdata_i18n(bibdata)
139
139
  super
140
140
  @lang == "ja" and date_translate(bibdata)
@@ -142,10 +142,58 @@ module IsoDoc
142
142
 
143
143
  def date_translate(bibdata)
144
144
  bibdata.xpath(ns("./date")).each do |d|
145
- d.children = @i18n.japanese_date(d.text.strip)
145
+ j = @i18n.japanese_date(d.text.strip)
146
+ @autonumbering_style == :japanese and
147
+ j.gsub!(/(\d+)/) do
148
+ $1.to_i.localize(:ja).spellout
149
+ end
150
+ d.children = j
146
151
  end
147
152
  end
148
153
 
154
+ def edition_translate(bibdata)
155
+ x = bibdata.at(ns("./edition")) or return
156
+ /^\d+$/.match?(x.text) or return
157
+ @i18n.edition_ordinal or return
158
+ num = x.text.to_i
159
+ @autonumbering_style == :japanese and num = num.localize(:ja).spellout
160
+ x.next =
161
+ %(<edition language="#{@lang}" numberonly="true">#{num}</edition>)
162
+ tag_translate(x, @lang, @i18n
163
+ .populate("edition_ordinal", { "var1" => num }))
164
+ end
165
+
166
+ def convert1(xml, filename, dir)
167
+ j = xml.at(ns("//metanorma-extension/presentation-metadata/" \
168
+ "autonumbering-style"))&.text
169
+ j ||= "arabic"
170
+ @autonumbering_style = j.to_sym
171
+ @xrefs.autonumbering_style = j.to_sym
172
+ super
173
+ end
174
+
175
+ def localized_strings(docxml)
176
+ super
177
+ a = docxml.at(ns("//localized-strings")) or return
178
+ ret = (0..1000).map do |i|
179
+ n = i.localize(:ja).spellout
180
+ "<localized-string key='#{i}' language='ja'>#{n}</localized-string>"
181
+ end.join("\n")
182
+ a << ret
183
+ end
184
+
185
+ def figure_fn(elem)
186
+ (elem.xpath(ns(".//fn")) - elem.xpath(ns("./name//fn")))
187
+ .each do |f|
188
+ table_fn1(elem, f, nil)
189
+ end
190
+ end
191
+
192
+ def omit_docid_prefix(prefix)
193
+ prefix.nil? || prefix.empty? and return true
194
+ super || %w(JIS).include?(prefix)
195
+ end
196
+
149
197
  include Init
150
198
  end
151
199
  end
@@ -29,7 +29,7 @@ module IsoDoc
29
29
  def make_tr_attr_style(cell, row, rowmax, totalrows, opt)
30
30
  top = row.zero? ? "#{SW1} 1.5pt;" : "none;"
31
31
  bottom = "#{SW1} #{rowmax >= totalrows ? '1.5' : '1.0'}pt;"
32
- ret = <<~STYLE.gsub(/\n/, "")
32
+ ret = <<~STYLE.delete("\n")
33
33
  border-top:#{top}mso-border-top-alt:#{top}
34
34
  border-left:#{bottom}mso-border-top-alt:#{bottom}
35
35
  border-right:#{bottom}mso-border-top-alt:#{bottom}
@@ -5,18 +5,41 @@ module IsoDoc
5
5
  return list["type"].to_sym if list["type"]
6
6
  return :alphabet if depth == 1
7
7
 
8
- :arabic
8
+ @style == :japanese ? :japanese : :arabic
9
9
  end
10
10
 
11
11
  def listlabel(_list, depth)
12
12
  case depth
13
13
  when 1 then (96 + @num).chr.to_s
14
- else @num.to_s
14
+ else
15
+ if @style == :japanese
16
+ @num.localize(:ja).spellout
17
+ else
18
+ @num.to_s
19
+ end
15
20
  end
16
21
  end
17
22
  end
18
23
 
19
24
  class Xref < IsoDoc::Iso::Xref
25
+ attr_accessor :autonumbering_style
26
+
27
+ def clause_sep
28
+ @autonumbering_style == :japanese ? "\u30fb" : "."
29
+ end
30
+
31
+ def clause_counter(num, opts)
32
+ opts[:numerals] ||= @autonumbering_style
33
+ opts[:separator] ||= clause_sep
34
+ super
35
+ end
36
+
37
+ def list_counter(num, opts)
38
+ opts[:numerals] ||= @autonumbering_style
39
+ opts[:separator] ||= clause_sep
40
+ IsoDoc::Jis::Counter.new(num, opts)
41
+ end
42
+
20
43
  def hierfigsep
21
44
  @lang == "ja" ? "の" : super
22
45
  end
@@ -28,12 +51,12 @@ module IsoDoc
28
51
  end
29
52
 
30
53
  def annex_name_lbl(clause, num)
31
- obl = l10n("(#{@labels['inform_annex']})")
54
+ obl = "(#{@labels['inform_annex']})"
32
55
  clause["obligation"] == "normative" and
33
- obl = l10n("(#{@labels['norm_annex']})")
56
+ obl = "(#{@labels['norm_annex']})"
34
57
  title = Common::case_with_markup(@labels["annex"], "capital",
35
58
  @script)
36
- l10n("#{title} #{num}<br/>#{obl}")
59
+ "#{title} #{num}<br/>#{obl}"
37
60
  end
38
61
 
39
62
  def annex_name_anchors1(clause, num, level)
@@ -44,7 +67,7 @@ module IsoDoc
44
67
 
45
68
  def annex_names1(clause, num, level)
46
69
  annex_name_anchors1(clause, num, level)
47
- i = ::IsoDoc::XrefGen::Counter.new(0, prefix: "#{num}.")
70
+ i = clause_counter(0, prefix: num)
48
71
  clause.xpath(ns(SUBCLAUSES)).each do |c|
49
72
  annex_names1(c, i.increment(c).print, level + 1)
50
73
  end
@@ -81,6 +104,16 @@ module IsoDoc
81
104
  super
82
105
  end
83
106
 
107
+ def main_anchor_names(xml)
108
+ n = Counter.new(0, { numerals: @autonumbering_style })
109
+ clause_order_main(xml).each do |a|
110
+ xml.xpath(ns(a[:path])).each do |c|
111
+ section_names(c, n, 1)
112
+ a[:multi] or break
113
+ end
114
+ end
115
+ end
116
+
84
117
  def back_clauses_anchor_names(xml)
85
118
  clause_order_back(xml).each do |a|
86
119
  xml.xpath(ns(a[:path])).each do |c|
@@ -96,7 +129,8 @@ module IsoDoc
96
129
 
97
130
  def commentary_names(clause)
98
131
  preface_name_anchors(clause, 1, clause_title(clause))
99
- clause.xpath(ns(SUBCLAUSES)).each_with_object(Counter.new) do |c, i|
132
+ clause.xpath(ns(SUBCLAUSES))
133
+ .each_with_object(clause_counter(0, {})) do |c, i|
100
134
  commentary_names1(c, clause["id"], i.increment(c).print, 2)
101
135
  end
102
136
  end
@@ -104,7 +138,7 @@ module IsoDoc
104
138
  def commentary_names1(clause, root, num, level)
105
139
  commentary_name_anchors(clause, num, root, level)
106
140
  clause.xpath(ns(SUBCLAUSES))
107
- .each_with_object(Counter.new(0, prefix: "#{num}.")) do |c, i|
141
+ .each_with_object(clause_counter(0, prefix: num)) do |c, i|
108
142
  commentary_names1(c, root, i.increment(c).print,
109
143
  level + 1)
110
144
  end
@@ -120,15 +154,19 @@ module IsoDoc
120
154
 
121
155
  def list_item_anchor_names(list, list_anchor, depth, prev_label,
122
156
  refer_list)
123
- c = Counter.new(list["start"] ? list["start"].to_i - 1 : 0)
157
+ c = list_counter(list["start"] ? list["start"].to_i - 1 : 0, {})
124
158
  list.xpath(ns("./li")).each do |li|
125
159
  bare_label, label =
126
- list_item_value(li, c, depth, { list_anchor: list_anchor,
127
- prev_label: prev_label, refer_list: depth == 1 ? refer_list : nil })
160
+ list_item_value(li, c, depth,
161
+ { list_anchor: list_anchor,
162
+ prev_label: prev_label,
163
+ refer_list: depth == 1 ? refer_list : nil })
128
164
  li["id"] and @anchors[li["id"]] =
129
- { label: bare_label, bare_xref: "#{bare_label})",
165
+ { label: bare_label,
166
+ bare_xref: "#{bare_label})",
130
167
  xref: "#{label})", type: "listitem",
131
- refer_list: refer_list, container: list_anchor[:container] }
168
+ refer_list: refer_list,
169
+ container: list_anchor[:container] }
132
170
  (li.xpath(ns(".//ol")) - li.xpath(ns(".//ol//ol"))).each do |ol|
133
171
  list_item_anchor_names(ol, list_anchor, depth + 1, label,
134
172
  refer_list)
@@ -139,10 +177,10 @@ refer_list)
139
177
  def list_item_value(entry, counter, depth, opts)
140
178
  label1 = counter.increment(entry).listlabel(entry.parent, depth)
141
179
  if depth > 2
142
- base = opts[:prev_label].match(/^(.*?)([0-9.]+)$/) # a) 1.1.1
143
- label1 = "#{base[2]}.#{label1}"
180
+ base = @c.decode(opts[:prev_label]).split(/\)\s*/) # List a) 1.1.1
181
+ label1 = "#{base[-1].sub(/^の/,'')}#{clause_sep}#{label1}"
144
182
  [label1, list_item_anchor_label(label1, opts[:list_anchor],
145
- base[1].sub(/[^a-z0-9]*$/, ""), opts[:refer_list])]
183
+ base[0].sub(/[\p{Zs})]+$/, ""), opts[:refer_list])]
146
184
  else
147
185
  [label1, list_item_anchor_label(label1, opts[:list_anchor], opts[:prev_label],
148
186
  opts[:refer_list])]
@@ -1783,9 +1783,21 @@ that the `number` given for the series applies to the second iteration of number
1783
1783
  May be used to differentiate rendering of notes in bibliographies</a:documentation>
1784
1784
  </attribute>
1785
1785
  </optional>
1786
- <ref name="LocalizedMarkedUpString">
1786
+ <ref name="LocalizedStringAttributes">
1787
1787
  <a:documentation>The content of the note</a:documentation>
1788
1788
  </ref>
1789
+ <choice>
1790
+ <oneOrMore>
1791
+ <ref name="BasicBlockNoId">
1792
+ <a:documentation>Multiple blocks of content</a:documentation>
1793
+ </ref>
1794
+ </oneOrMore>
1795
+ <oneOrMore>
1796
+ <ref name="TextElement">
1797
+ <a:documentation>Single block of content</a:documentation>
1798
+ </ref>
1799
+ </oneOrMore>
1800
+ </choice>
1789
1801
  </element>
1790
1802
  </define>
1791
1803
  <define name="bibabstract">
@@ -17,7 +17,7 @@
17
17
  these elements; we just want one namespace for any child grammars
18
18
  of this.
19
19
  -->
20
- <!-- VERSION v1.3.4 -->
20
+ <!-- VERSION v1.4.0 -->
21
21
  <grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
22
22
  <include href="reqt.rng"/>
23
23
  <include href="basicdoc.rng">
@@ -326,7 +326,7 @@ normative or informative references, some split references into sections organiz
326
326
  <a:documentation>Content of note</a:documentation>
327
327
  <oneOrMore>
328
328
  <choice>
329
- <ref name="paragraph"/>
329
+ <ref name="paragraph-with-footnote"/>
330
330
  <ref name="ul"/>
331
331
  <ref name="ol"/>
332
332
  <ref name="dl"/>
@@ -412,7 +412,7 @@ normative or informative references, some split references into sections organiz
412
412
  <element name="note">
413
413
  <ref name="OptionalId"/>
414
414
  <oneOrMore>
415
- <ref name="paragraph"/>
415
+ <ref name="paragraph-with-footnote"/>
416
416
  </oneOrMore>
417
417
  </element>
418
418
  </define>
@@ -1977,7 +1977,7 @@ used in document amendments</a:documentation>
1977
1977
  <oneOrMore>
1978
1978
  <choice>
1979
1979
  <a:documentation>Content of the verbal representation of the term</a:documentation>
1980
- <ref name="paragraph"/>
1980
+ <ref name="paragraph-with-footnote"/>
1981
1981
  <ref name="dl"/>
1982
1982
  <ref name="ol"/>
1983
1983
  <ref name="ul"/>
@@ -2015,7 +2015,7 @@ used in document amendments</a:documentation>
2015
2015
  <oneOrMore>
2016
2016
  <choice>
2017
2017
  <a:documentation>Content of the term note</a:documentation>
2018
- <ref name="paragraph"/>
2018
+ <ref name="paragraph-with-footnote"/>
2019
2019
  <ref name="ul"/>
2020
2020
  <ref name="ol"/>
2021
2021
  <ref name="dl"/>
@@ -2037,7 +2037,7 @@ used in document amendments</a:documentation>
2037
2037
  <ref name="dl"/>
2038
2038
  <ref name="quote"/>
2039
2039
  <ref name="sourcecode"/>
2040
- <ref name="paragraph"/>
2040
+ <ref name="paragraph-with-footnote"/>
2041
2041
  <ref name="figure"/>
2042
2042
  </choice>
2043
2043
  </oneOrMore>
@@ -23,6 +23,14 @@ module Metanorma
23
23
  "STIX Two Math" => nil,
24
24
  "IPAexGothic" => nil,
25
25
  "IPAexMincho" => nil,
26
+ =begin
27
+ "Noto Serif JP" => nil,
28
+ "Noto Serif JP ExtraLight" => nil,
29
+ "Noto Serif JP Medium" => nil,
30
+ "Noto Serif JP Black" => nil,
31
+ "Noto Sans JP Thin" => nil,
32
+ "Noto Sans JP Medium" => nil,
33
+ =end
26
34
  "Courier New" => nil,
27
35
  "Cambria Math" => nil,
28
36
  "Times New Roman" => nil,
@@ -1,6 +1,6 @@
1
1
  module Metanorma
2
2
  module Jis
3
- VERSION = "0.3.6".freeze
3
+ VERSION = "0.4.0".freeze
4
4
  end
5
5
  end
6
6
 
@@ -6,15 +6,19 @@ module Relaton
6
6
  class Parse < ::Relaton::Render::Iso::Parse
7
7
  def simple_or_host_xml2hash(doc, host)
8
8
  ret = super
9
- ret.merge(home_standard: home_standard(doc, ret[:publisher_raw] ||
10
- ret[:author_raw]))
9
+ orgs = %i(publisher_raw author_raw authorizer_raw)
10
+ .each_with_object([]) do |i, m|
11
+ ret[i] and m << ret[i]
12
+ end
13
+ ret.merge(home_standard: home_standard(doc, orgs.flatten))
11
14
  end
12
15
 
13
16
  def home_standard(_doc, pubs)
14
17
  pubs&.any? do |r|
15
18
  ["International Organization for Standardization", "ISO",
16
19
  "International Electrotechnical Commission", "IEC",
17
- "一般財団法人 日本規格協会", "Japanese Industrial Standards"]
20
+ "日本規格協会", "一般財団法人 日本規格協会",
21
+ "Japanese Industrial Standards"]
18
22
  .include?(r[:nonpersonal])
19
23
  end
20
24
  end
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.required_ruby_version = Gem::Requirement.new(">= 3.1.0")
32
32
 
33
33
  spec.add_dependency "japanese_calendar", "~> 0"
34
- spec.add_dependency "metanorma-iso", "~> 2.8.0"
34
+ spec.add_dependency "metanorma-iso", "~> 2.9.0"
35
35
  spec.add_dependency "pubid"
36
36
 
37
37
  spec.add_development_dependency "debug"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma-jis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-14 00:00:00.000000000 Z
11
+ date: 2024-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: japanese_calendar
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 2.8.0
33
+ version: 2.9.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 2.8.0
40
+ version: 2.9.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pubid
43
43
  requirement: !ruby/object:Gem::Requirement