metanorma-gb 1.4.1 → 1.5.2

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: 8e077fbc8c1b78bd762f3f835e746c9ef3962b7b006b1d2f52b0ceb1f456a60b
4
- data.tar.gz: e96cd7481cafe9c70008beca81331c3cd5fc39f76ffa90d27befe94311ce8fbf
3
+ metadata.gz: b5662bd2a89d7f19742aff02ee97b11c969ddf2273a4c4c2c14bf132ae98ede0
4
+ data.tar.gz: 310abd14a35050944a66c8235dbcaba7e18f7b098197eaff97cd5c35b0d94072
5
5
  SHA512:
6
- metadata.gz: 95871f762fadc540a35ec9676d97a14f8c1996afa33d09525b22d603224e199fb284e82a762b84a7da10f554548511ee20c1ce3210df0ee96478cb0079fb2e49
7
- data.tar.gz: 5a102ff4ecb8556943d21d66f73f1744a84bce3b27e8e8649c8feef778ad854a1d69ca94735952d823f287323e4d2b9875c41249671d857e4ec81416954257cd
6
+ metadata.gz: 44e55243c2ea223e56533bb754fdcc5fa6ab88e3b0fe53f1f38891309708722f0d772b7bcfd94a1ebbdc398211f78437750f1049939967d642e86f382ad283aa
7
+ data.tar.gz: ecc65cc027fe5cf66e125f156b601187d35ac89d8b0541284960e053da3bf15cd99d87decacfb2d928d2665833ab427850220299efa2022190fd39c2ecdb7b0f
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
data/Gemfile CHANGED
@@ -3,7 +3,6 @@ Encoding.default_internal = Encoding::UTF_8
3
3
 
4
4
  source "https://rubygems.org"
5
5
  git_source(:github) { |repo| "https://github.com/#{repo}" }
6
-
7
6
  gemspec
8
7
 
9
8
  if File.exist? 'Gemfile.devel'
data/Rakefile CHANGED
@@ -1,6 +1,23 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require 'isodoc/gem_tasks'
3
4
 
5
+ module IsoDoc
6
+ module GemTasks
7
+ module_function
8
+
9
+ def fonts_placeholder
10
+ <<~TEXT
11
+ $bodyfont: '{{bodyfont}}';
12
+ $headerfont: '{{headerfont}}';
13
+ $monospacefont: '{{monospacefont}}';
14
+ $titlefont: '{{titlefont}}';
15
+ TEXT
16
+ end
17
+ end
18
+ end
19
+
20
+ IsoDoc::GemTasks.install
4
21
  RSpec::Core::RakeTask.new(:spec)
5
22
 
6
23
  task :default => :spec
@@ -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": "标准草案工作组讨论稿",
@@ -15,7 +15,7 @@ module Asciidoctor
15
15
 
16
16
  def stage_name(stage, substage)
17
17
  return "Proof" if stage == "60" && substage == "00"
18
- @language == "en" ?
18
+ @lang == "en" ?
19
19
  STAGE_NAMES[stage.to_sym] : STAGE_ABBRS_CN[stage.to_sym]
20
20
  end
21
21
 
@@ -43,7 +43,7 @@ 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
48
  node.attr("draft"), node.attr("doctype"))
49
49
  dn = "/#{abbr} #{dn}" # prefixes added in cleanup
@@ -922,6 +922,9 @@
922
922
  <optional>
923
923
  <attribute name="script"/>
924
924
  </optional>
925
+ <optional>
926
+ <attribute name="type"/>
927
+ </optional>
925
928
  <optional>
926
929
  <attribute name="obligation">
927
930
  <choice>
@@ -961,9 +964,6 @@
961
964
  </define>
962
965
  <define name="content-subsection">
963
966
  <element name="clause">
964
- <optional>
965
- <attribute name="type"/>
966
- </optional>
967
967
  <ref name="Content-Section"/>
968
968
  </element>
969
969
  </define>
@@ -992,6 +992,9 @@
992
992
  </choice>
993
993
  </attribute>
994
994
  </optional>
995
+ <optional>
996
+ <attribute name="type"/>
997
+ </optional>
995
998
  <optional>
996
999
  <ref name="section-title"/>
997
1000
  </optional>
@@ -1011,9 +1014,6 @@
1011
1014
  </define>
1012
1015
  <define name="clause">
1013
1016
  <element name="clause">
1014
- <optional>
1015
- <attribute name="type"/>
1016
- </optional>
1017
1017
  <ref name="Clause-Section"/>
1018
1018
  </element>
1019
1019
  </define>
@@ -1042,6 +1042,9 @@
1042
1042
  </choice>
1043
1043
  </attribute>
1044
1044
  </optional>
1045
+ <optional>
1046
+ <attribute name="type"/>
1047
+ </optional>
1045
1048
  <optional>
1046
1049
  <ref name="section-title"/>
1047
1050
  </optional>
@@ -1180,6 +1183,9 @@
1180
1183
  <optional>
1181
1184
  <attribute name="script"/>
1182
1185
  </optional>
1186
+ <optional>
1187
+ <attribute name="type"/>
1188
+ </optional>
1183
1189
  <optional>
1184
1190
  <attribute name="obligation">
1185
1191
  <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")