metanorma-gb 1.4.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8174bc7b39fa8089f62c94500ef94424ecbc48ac4ebe78022873307e2b619da5
4
- data.tar.gz: 88b8c6ba983a7f49648edcf1839536bd947784b549bd29a9ced0a9bf2496d9e6
3
+ metadata.gz: f15254a6924cabb7e72a3c884ab558e4001ba7681f674a916c7912ff9143eb35
4
+ data.tar.gz: 2530f7cc96ff18c30c696c4ac91f97627e3c733654bbcf329f3779ab3f1ef3a8
5
5
  SHA512:
6
- metadata.gz: e6c702a9ea7b33d36a7d2ed08a12966472c475268037a19ca1f94a272d34a63a58b14090fb92b9f7ee066b6d879cabf01f35eacd91b4d794b62a71f4721b94ab
7
- data.tar.gz: 6da57b1874fbff0ea896bd645d930a44c161647bc6a392848d5cb9244d7e7e8c6373ea08de696d44bfb1e4c6ffae4f6da9134e0e552a3b05368f3de34f9a07e0
6
+ metadata.gz: '09ebcf85bc0b1cc309e1f596db16868ab72318dd2f879962c43e5931086a20c0ca188df17d234e415a36c185e44d09bd51f7f47679b39859d4ff09c50ae6acb9'
7
+ data.tar.gz: 2a28bcb07db7821921006de304215e2f0a859e1f4e274dbeda6cead2ce7c3e5242bab9df911e624561261d1cdfbeadb9a11358ce19cea10a5ad55d67b9064266
data/.gitignore CHANGED
@@ -3,7 +3,5 @@ coverage/
3
3
  .rspec_status
4
4
  .tmp.xml
5
5
  gb-issuer-default.gif
6
- gb.css
7
- htmlstyle.css
8
6
  test.html
9
7
  test.xml
@@ -0,0 +1,130 @@
1
+ module Asciidoctor
2
+ module Gb
3
+ class Converter < ISO::Converter
4
+ def termdef_cleanup(xmldoc)
5
+ super
6
+ # TODO this should become variant tag
7
+ localisedstr(xmldoc)
8
+ end
9
+
10
+ ROMAN_TEXT = /\s*[a-z\u00c0-\u00d6\u00d8-\u00f0\u0100-\u0240]/i
11
+ HAN_TEXT = /\s*[\u4e00-\u9fff]+/
12
+
13
+ LOCALISED_ELEMS = "//admitted | //deprecates | //preferred | //prefix | "\
14
+ "//initial | //addition | //surname | //forename | //name | "\
15
+ "//abbreviation | //role/description | //affiliation/description | "\
16
+ "//bibdata/item | //bibitem/title | //bibdata/formattedref | "\
17
+ "//bibitem/formattedref | //bibdata/note | //bibitem/note | "\
18
+ "//bibdata/abstract | //bibitem/note ".freeze
19
+
20
+ MUST_LOCALISE_ELEMS = %w{admitted deprecates preferred}.freeze
21
+
22
+ def localisedstr(xmldoc)
23
+ xmldoc.xpath(LOCALISED_ELEMS).each do |zh|
24
+ if zh.at("./string")
25
+ extract_localisedstrings(zh)
26
+ elsif MUST_LOCALISE_ELEMS.include? zh.name
27
+ duplicate_localisedstrings(zh)
28
+ end
29
+ end
30
+ end
31
+
32
+ # element consists solely of localised strings, with no attributes
33
+ def extract_localisedstrings(elem)
34
+ elem.xpath("./string").each do |s|
35
+ s.name = elem.name
36
+ end
37
+ elem.replace(elem.children)
38
+ end
39
+
40
+ def text_clean(text)
41
+ text.gsub(/^\s*/, "").gsub(/</, "&lt;").gsub(/>/, "&gt;")
42
+ end
43
+
44
+ def duplicate_localisedstrings(zh)
45
+ en = zh.dup.remove
46
+ zh.after(en).after(" ")
47
+ zh["language"] = "zh"
48
+ en["language"] = "en"
49
+ en.traverse do |c|
50
+ c.text? && c.content = text_clean(c.text.gsub(HAN_TEXT, ""))
51
+ end
52
+ zh.traverse do |c|
53
+ c.text? && c.content = text_clean(c.text.gsub(ROMAN_TEXT, ""))
54
+ end
55
+ end
56
+
57
+ def termdef_boilerplate_cleanup(xmldoc)
58
+ return if @keepboilerplate
59
+ super
60
+ end
61
+
62
+ def cleanup(xmldoc)
63
+ lang = xmldoc.at("//language")&.text
64
+ @agencyclass = GbAgencies::Agencies.new(lang, {}, "")
65
+ super
66
+ contributor_cleanup(xmldoc)
67
+ xmldoc
68
+ end
69
+
70
+ def docidentifier_cleanup(xmldoc)
71
+ id = xmldoc.at("//bibdata/docidentifier[@type = 'gb']") or return
72
+ scope = xmldoc.at("//gbscope")&.text
73
+ prefix = xmldoc.at("//gbprefix")&.text
74
+ mand = xmldoc.at("//gbmandate")&.text || "mandatory"
75
+ idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
76
+ id.content = idtext&.gsub(/\&#x2002;/, " ")
77
+ id = xmldoc.at("//bibdata/ext/structuredidentifier/"\
78
+ "project-number") or return
79
+ idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
80
+ id.content = idtext&.gsub(/\&#x2002;/, " ")
81
+ end
82
+
83
+ def committee_cleanup(xmldoc)
84
+ xmldoc.xpath("//gbcommittee").each do |c|
85
+ xmldoc.at("//bibdata/contributor").next =
86
+ "<contributor><role type='technical-committee'/><organization>"\
87
+ "<name>#{c.text}</name></organization></contributor>"
88
+ end
89
+ end
90
+
91
+ def agency_value(issuer, scope, prefix, mandate)
92
+ agency = issuer.content
93
+ agency == "GB" and
94
+ agency = @agencyclass.standard_agency1(scope, prefix, mandate)
95
+ agency = "GB" if agency.nil? || agency.empty?
96
+ agency
97
+ end
98
+
99
+ def contributor_cleanup(xmldoc)
100
+ issuer = xmldoc.at("//bibdata/contributor[role/@type = 'issuer']/"\
101
+ "organization/name")
102
+ scope = xmldoc.at("//gbscope")&.text
103
+ prefix = xmldoc.at("//gbprefix")&.text
104
+ mandate = xmldoc.at("//gbmandate")&.text || "mandatory"
105
+ agency = agency_value(issuer, scope, prefix, mandate)
106
+ owner = xmldoc.at("//copyright/owner/organization/name")
107
+ owner.content = agency
108
+ issuer.content = agency
109
+ committee_cleanup(xmldoc)
110
+ end
111
+
112
+ def omit_docid_prefix(prefix)
113
+ IsoDoc::Gb::HtmlConvert.new({}).omit_docid_prefix(prefix)
114
+ end
115
+
116
+ def boilerplate_cleanup(xmldoc)
117
+ isodoc = boilerplate_isodoc(xmldoc)
118
+ initial_boilerplate(xmldoc, isodoc)
119
+ return if @keepboilerplate
120
+ xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
121
+ term_defs_boilerplate(f.at("./title"),
122
+ xmldoc.xpath(".//termdocsource"),
123
+ f.at(".//term"), f.at(".//p"), isodoc)
124
+ end
125
+ f = xmldoc.at(self.class::NORM_REF) and
126
+ norm_ref_preface(f)
127
+ end
128
+ end
129
+ end
130
+ end
@@ -1,6 +1,5 @@
1
1
  require "asciidoctor"
2
2
  require "asciidoctor/iso/converter"
3
- require "metanorma/gb/version"
4
3
  require "isodoc/gb/common"
5
4
  require "isodoc/gb/word_convert"
6
5
  require "isodoc/gb/pdf_convert"
@@ -9,6 +8,7 @@ require "gb_agencies"
9
8
  require_relative "./section_input.rb"
10
9
  require_relative "./front.rb"
11
10
  require_relative "./validate.rb"
11
+ require_relative "cleanup.rb"
12
12
  require "fileutils"
13
13
 
14
14
  module Asciidoctor
@@ -74,62 +74,15 @@ module Asciidoctor
74
74
  def outputs(node, ret)
75
75
  File.open(@filename + ".xml", "w:UTF-8") { |f| f.write(ret) }
76
76
  presentation_xml_converter(node).convert(@filename + ".xml")
77
- html_compliant_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}_compliant.html")
78
- html_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.html")
79
- doc_converter(node).convert(@filename + ".presentation.xml", nil, false, "#{@filename}.doc")
80
- pdf_converter(node)&.convert(@filename + ".presentation.xml", nil, false, "#{@filename}.pdf")
81
- end
82
-
83
- def termdef_cleanup(xmldoc)
84
- super
85
- localisedstr(xmldoc)
86
- end
87
-
88
- ROMAN_TEXT = /\s*[a-z\u00c0-\u00d6\u00d8-\u00f0\u0100-\u0240]/i
89
- HAN_TEXT = /\s*[\u4e00-\u9fff]+/
90
-
91
- LOCALISED_ELEMS = "//admitted | //deprecates | //preferred | //prefix | "\
92
- "//initial | //addition | //surname | //forename | //name | "\
93
- "//abbreviation | //role/description | //affiliation/description | "\
94
- "//bibdata/item | //bibitem/title | //bibdata/formattedref | "\
95
- "//bibitem/formattedref | //bibdata/note | //bibitem/note | "\
96
- "//bibdata/abstract | //bibitem/note ".freeze
97
-
98
- MUST_LOCALISE_ELEMS = %w{admitted deprecates preferred}.freeze
99
-
100
- def localisedstr(xmldoc)
101
- xmldoc.xpath(LOCALISED_ELEMS).each do |zh|
102
- if zh.at("./string")
103
- extract_localisedstrings(zh)
104
- elsif MUST_LOCALISE_ELEMS.include? zh.name
105
- duplicate_localisedstrings(zh)
106
- end
107
- end
108
- end
109
-
110
- # element consists solely of localised strings, with no attributes
111
- def extract_localisedstrings(elem)
112
- elem.xpath("./string").each do |s|
113
- s.name = elem.name
114
- end
115
- elem.replace(elem.children)
116
- end
117
-
118
- def text_clean(text)
119
- text.gsub(/^\s*/, "").gsub(/</, "&lt;").gsub(/>/, "&gt;")
120
- end
121
-
122
- def duplicate_localisedstrings(zh)
123
- en = zh.dup.remove
124
- zh.after(en).after(" ")
125
- zh["language"] = "zh"
126
- en["language"] = "en"
127
- en.traverse do |c|
128
- c.text? && c.content = text_clean(c.text.gsub(HAN_TEXT, ""))
129
- end
130
- zh.traverse do |c|
131
- c.text? && c.content = text_clean(c.text.gsub(ROMAN_TEXT, ""))
132
- end
77
+ html_compliant_converter(node).
78
+ convert(@filename + ".presentation.xml",
79
+ nil, false, "#{@filename}_compliant.html")
80
+ html_converter(node).convert(@filename + ".presentation.xml",
81
+ nil, false, "#{@filename}.html")
82
+ doc_converter(node).convert(@filename + ".presentation.xml",
83
+ nil, false, "#{@filename}.doc")
84
+ pdf_converter(node)&.convert(@filename + ".presentation.xml",
85
+ nil, false, "#{@filename}.pdf")
133
86
  end
134
87
 
135
88
  def inline_quoted(node)
@@ -149,11 +102,6 @@ module Asciidoctor
149
102
  super
150
103
  end
151
104
 
152
- def termdef_boilerplate_cleanup(xmldoc)
153
- return if @keepboilerplate
154
- super
155
- end
156
-
157
105
  GBCODE = "((AQ|BB|CB|CH|CJ|CY|DA|DB|DL|DZ|EJ|FZ|GA|GH|GM|GY|HB|HG|"\
158
106
  "HJ|HS|HY|JB|JC|JG|JR|JT|JY|LB|LD|LS|LY|MH|MT|MZ|NY|QB|QC|QJ|"\
159
107
  "QZ|SB|SC|SH|SJ|SN|SY|TB|TD|TJ|TY|WB|WH|WJ|WM|WS|WW|XB|YB|YC|"\
@@ -186,71 +134,12 @@ module Asciidoctor
186
134
  super
187
135
  end
188
136
 
189
- def cleanup(xmldoc)
190
- lang = xmldoc.at("//language")&.text
191
- @agencyclass = GbAgencies::Agencies.new(lang, {}, "")
137
+ def init(node)
138
+ node.attr("language") or node.set_attr("language", "zh")
139
+ node.attr("script") or
140
+ node.set_attr("script", node.attr("language") == "zh" ?
141
+ "Hans" : "Latn")
192
142
  super
193
- contributor_cleanup(xmldoc)
194
- xmldoc
195
- end
196
-
197
- def docidentifier_cleanup(xmldoc)
198
- id = xmldoc.at("//bibdata/docidentifier[@type = 'gb']") or return
199
- scope = xmldoc.at("//gbscope")&.text
200
- prefix = xmldoc.at("//gbprefix")&.text
201
- mand = xmldoc.at("//gbmandate")&.text || "mandatory"
202
- idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
203
- id.content = idtext&.gsub(/\&#x2002;/, " ")
204
- id = xmldoc.at("//bibdata/ext/structuredidentifier/"\
205
- "project-number") or return
206
- idtext = @agencyclass.docidentifier(scope, prefix, mand, nil, id.text)
207
- id.content = idtext&.gsub(/\&#x2002;/, " ")
208
- end
209
-
210
- def committee_cleanup(xmldoc)
211
- xmldoc.xpath("//gbcommittee").each do |c|
212
- xmldoc.at("//bibdata/contributor").next =
213
- "<contributor><role type='technical-committee'/><organization>"\
214
- "<name>#{c.text}</name></organization></contributor>"
215
- end
216
- end
217
-
218
- def agency_value(issuer, scope, prefix, mandate)
219
- agency = issuer.content
220
- agency == "GB" and
221
- agency = @agencyclass.standard_agency1(scope, prefix, mandate)
222
- agency = "GB" if agency.nil? || agency.empty?
223
- agency
224
- end
225
-
226
- def contributor_cleanup(xmldoc)
227
- issuer = xmldoc.at("//bibdata/contributor[role/@type = 'issuer']/"\
228
- "organization/name")
229
- scope = xmldoc.at("//gbscope")&.text
230
- prefix = xmldoc.at("//gbprefix")&.text
231
- mandate = xmldoc.at("//gbmandate")&.text || "mandatory"
232
- agency = agency_value(issuer, scope, prefix, mandate)
233
- owner = xmldoc.at("//copyright/owner/organization/name")
234
- owner.content = agency
235
- issuer.content = agency
236
- committee_cleanup(xmldoc)
237
- end
238
-
239
- def omit_docid_prefix(prefix)
240
- IsoDoc::Gb::HtmlConvert.new({}).omit_docid_prefix(prefix)
241
- end
242
-
243
- def boilerplate_cleanup(xmldoc)
244
- isodoc = boilerplate_isodoc(xmldoc)
245
- initial_boilerplate(xmldoc, isodoc)
246
- return if @keepboilerplate
247
- xmldoc.xpath(self.class::TERM_CLAUSE).each do |f|
248
- term_defs_boilerplate(f.at("./title"),
249
- xmldoc.xpath(".//termdocsource"),
250
- f.at(".//term"), f.at(".//p"), isodoc)
251
- end
252
- f = xmldoc.at(self.class::NORM_REF) and
253
- norm_ref_preface(f)
254
143
  end
255
144
  end
256
145
  end
@@ -1,7 +1,7 @@
1
1
  module Asciidoctor
2
2
  module Gb
3
3
  class Converter < ISO::Converter
4
- STAGE_ABBRS_CN = {
4
+ STAGE_ABBRS_CN = {
5
5
  "00": "新工作项目建议",
6
6
  "10": "新工作项目",
7
7
  "20": "标准草案工作组讨论稿",
@@ -43,9 +43,9 @@ module Asciidoctor
43
43
 
44
44
  def id_stage_prefix(dn, node)
45
45
  if node.attr("docstage") && node.attr("docstage").to_i < 60
46
- abbr = IsoDoc::Gb::Metadata.new("en", "Latn", {}).
46
+ abbr = IsoDoc::Gb::Metadata.new("en", "Latn", @i18n).
47
47
  status_abbrev(node.attr("docstage"), nil, node.attr("iteration"),
48
- node.attr("draft"), node.attr("doctype"))
48
+ node.attr("draft"), doctype(node))
49
49
  dn = "/#{abbr} #{dn}" # prefixes added in cleanup
50
50
  else
51
51
  dn += "-#{node.attr("copyright-year")}" if node.attr("copyright-year")
@@ -42,8 +42,11 @@
42
42
  </define>
43
43
  <define name="xref">
44
44
  <element name="xref">
45
+ <!-- attribute target { xsd:IDREF }, -->
45
46
  <attribute name="target">
46
- <data type="IDREF"/>
47
+ <data type="string">
48
+ <param name="pattern">\i\c*|\c+#\c+</param>
49
+ </data>
47
50
  </attribute>
48
51
  <optional>
49
52
  <attribute name="type">
@@ -922,6 +925,9 @@
922
925
  <optional>
923
926
  <attribute name="script"/>
924
927
  </optional>
928
+ <optional>
929
+ <attribute name="type"/>
930
+ </optional>
925
931
  <optional>
926
932
  <attribute name="obligation">
927
933
  <choice>
@@ -961,9 +967,6 @@
961
967
  </define>
962
968
  <define name="content-subsection">
963
969
  <element name="clause">
964
- <optional>
965
- <attribute name="type"/>
966
- </optional>
967
970
  <ref name="Content-Section"/>
968
971
  </element>
969
972
  </define>
@@ -992,6 +995,9 @@
992
995
  </choice>
993
996
  </attribute>
994
997
  </optional>
998
+ <optional>
999
+ <attribute name="type"/>
1000
+ </optional>
995
1001
  <optional>
996
1002
  <ref name="section-title"/>
997
1003
  </optional>
@@ -1011,9 +1017,6 @@
1011
1017
  </define>
1012
1018
  <define name="clause">
1013
1019
  <element name="clause">
1014
- <optional>
1015
- <attribute name="type"/>
1016
- </optional>
1017
1020
  <ref name="Clause-Section"/>
1018
1021
  </element>
1019
1022
  </define>
@@ -1042,6 +1045,9 @@
1042
1045
  </choice>
1043
1046
  </attribute>
1044
1047
  </optional>
1048
+ <optional>
1049
+ <attribute name="type"/>
1050
+ </optional>
1045
1051
  <optional>
1046
1052
  <ref name="section-title"/>
1047
1053
  </optional>
@@ -1180,6 +1186,9 @@
1180
1186
  <optional>
1181
1187
  <attribute name="script"/>
1182
1188
  </optional>
1189
+ <optional>
1190
+ <attribute name="type"/>
1191
+ </optional>
1183
1192
  <optional>
1184
1193
  <attribute name="obligation">
1185
1194
  <choice>
@@ -8,6 +8,8 @@ module Asciidoctor
8
8
  class Converter < ISO::Converter
9
9
  def sectiontype_streamline(ret)
10
10
  case ret
11
+ when "前言" then "foreword"
12
+ when "致謝" then "acknowledgements"
11
13
  when "引言" then "introduction"
12
14
  when "范围" then "scope"
13
15
  when "规范性引用文件" then "normative references"
@@ -21,6 +23,15 @@ module Asciidoctor
21
23
  end
22
24
  end
23
25
 
26
+ def symbols_attrs(node, a)
27
+ case sectiontype1(node)
28
+ when "符号" then a.merge(type: "symbols")
29
+ when "代号和缩略语" then a.merge(type: "abbreviated_terms")
30
+ else
31
+ super
32
+ end
33
+ end
34
+
24
35
  def appendix_parse(attrs, xml, node)
25
36
  # UNSAFE, there is no unset_option() in asciidoctor
26
37
  node.remove_attr("appendix-option")
@@ -1,7 +1,6 @@
1
1
  module Asciidoctor
2
2
  module Gb
3
3
  class Converter < ISO::Converter
4
-
5
4
  def validate(doc)
6
5
  content_validate(doc)
7
6
  schema_validate(formattedstr_strip(doc.dup),