metanorma-iso 1.10.0 → 1.10.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ubuntu.yml +41 -0
  3. data/Gemfile +3 -4
  4. data/Makefile +44 -0
  5. data/Rakefile +1 -1
  6. data/bin/rspec +1 -2
  7. data/lib/asciidoctor/iso/base.rb +1 -1
  8. data/lib/asciidoctor/iso/cleanup.rb +7 -6
  9. data/lib/asciidoctor/iso/front.rb +2 -2
  10. data/lib/asciidoctor/iso/isodoc.rng +68 -18
  11. data/lib/asciidoctor/iso/isostandard.rng +14 -0
  12. data/lib/asciidoctor/iso/section.rb +1 -1
  13. data/lib/asciidoctor/iso/validate.rb +1 -1
  14. data/lib/asciidoctor/iso/validate_section.rb +1 -1
  15. data/lib/isodoc/iso/html/isodoc.css +0 -1
  16. data/lib/isodoc/iso/html/isodoc.scss +0 -1
  17. data/lib/isodoc/iso/html/style-human.css +21 -1
  18. data/lib/isodoc/iso/html/style-human.scss +26 -1
  19. data/lib/isodoc/iso/html/style-iso.css +21 -1
  20. data/lib/isodoc/iso/html/style-iso.scss +26 -1
  21. data/lib/isodoc/iso/html_convert.rb +81 -22
  22. data/lib/isodoc/iso/i18n.rb +10 -9
  23. data/lib/isodoc/iso/iso.amendment.xsl +304 -118
  24. data/lib/isodoc/iso/iso.international-standard.xsl +304 -118
  25. data/lib/isodoc/iso/isosts_convert.rb +6 -2
  26. data/lib/isodoc/iso/presentation_xml_convert.rb +19 -9
  27. data/lib/isodoc/iso/sections.rb +2 -0
  28. data/lib/isodoc/iso/sts_convert.rb +5 -2
  29. data/lib/isodoc/iso/word_cleanup.rb +94 -0
  30. data/lib/isodoc/iso/word_convert.rb +12 -91
  31. data/lib/metanorma/iso/processor.rb +2 -2
  32. data/lib/metanorma/iso/version.rb +1 -1
  33. data/metanorma-iso.gemspec +3 -3
  34. data/spec/asciidoctor/base_spec.rb +543 -209
  35. data/spec/asciidoctor/blocks_spec.rb +4 -43
  36. data/spec/asciidoctor/cleanup_spec.rb +15 -12
  37. data/spec/asciidoctor/refs_spec.rb +174 -88
  38. data/spec/isodoc/i18n_spec.rb +32 -18
  39. data/spec/isodoc/inline_spec.rb +4 -4
  40. data/spec/isodoc/postproc_spec.rb +111 -28
  41. data/spec/isodoc/section_spec.rb +3 -3
  42. data/spec/isodoc/table_spec.rb +6 -8
  43. data/spec/isodoc/terms_spec.rb +30 -37
  44. data/spec/isodoc/xref_spec.rb +3 -3
  45. data/spec/metanorma/processor_spec.rb +110 -14
  46. data/spec/vcr_cassettes/docrels.yml +783 -0
  47. data/spec/vcr_cassettes/sortrefs.yml +599 -0
  48. metadata +12 -8
@@ -57,7 +57,7 @@ module IsoDoc
57
57
  ret += " 第#{from.text}" if from
58
58
  ret += "–#{upto.text}" if upto
59
59
  loc = (@i18n.locality[type] || type.sub(/^locality:/, "").capitalize)
60
- ret += " #{loc}" unless subsection && type == "clause" ||
60
+ ret += " #{loc}" unless (subsection && type == "clause") ||
61
61
  type == "list" || target.match(/^IEV$|^IEC 60050-/) ||
62
62
  node["droploc"] == "true"
63
63
  ret += ")" if type == "list"
@@ -73,8 +73,8 @@ module IsoDoc
73
73
  return l10n(eref_localities1_zh(target, type, from, upto, node,
74
74
  delim))
75
75
  ret = eref_delim(delim, type)
76
- ret += eref_locality_populate(type, node) unless subsection &&
77
- type == "clause" || type == "list" ||
76
+ ret += eref_locality_populate(type, node) unless (subsection &&
77
+ type == "clause") || type == "list" ||
78
78
  target.match(/^IEV$|^IEC 60050-/)
79
79
  ret += " #{from.text}" if from
80
80
  ret += "–#{upto.text}" if upto
@@ -163,17 +163,27 @@ module IsoDoc
163
163
  i = display_order_xpath(docxml, "//preface/*", i)
164
164
  i = display_order_at(docxml, "//clause[@type = 'scope']", i)
165
165
  i = display_order_at(docxml, @xrefs.klass.norm_ref_xpath, i)
166
- # i = display_order_at(docxml, "//sections/terms | "\
167
- # "//sections/clause[descendant::terms]", i)
168
- # i = display_order_at(docxml, "//sections/definitions", i)
169
- # i = display_order_xpath(docxml, @xrefs.klass.middle_clause(docxml), i)
170
- i = display_order_xpath(docxml, "//sections/clause[not(@type = 'scope')] | "\
171
- "//sections/terms | //sections/definitions", i)
166
+ i = display_order_xpath(docxml,
167
+ "//sections/clause[not(@type = 'scope')] | "\
168
+ "//sections/terms | //sections/definitions", i)
172
169
  i = display_order_xpath(docxml, "//annex", i)
173
170
  i = display_order_xpath(docxml, @xrefs.klass.bibliography_xpath, i)
174
171
  display_order_xpath(docxml, "//indexsect", i)
175
172
  end
176
173
 
174
+ def termdefinition1(elem)
175
+ prefix_domain_to_definition(elem)
176
+ super
177
+ end
178
+
179
+ def prefix_domain_to_definition(elem)
180
+ ((d = elem.at(ns("./domain"))) &&
181
+ (v = elem.at(ns("./definition/verbal-definition"))) &&
182
+ v.elements.first.name == "p") or return
183
+ v.elements.first.children.first.previous =
184
+ "<#{d.remove.children.to_xml}> "
185
+ end
186
+
177
187
  include Init
178
188
  end
179
189
  end
@@ -49,12 +49,14 @@ module IsoDoc
49
49
 
50
50
  def foreword(isoxml, out)
51
51
  f = isoxml.at(ns("//foreword")) || return
52
+ @foreword = true
52
53
  page_break(out)
53
54
  out.div **attr_code(id: f["id"]) do |s|
54
55
  clause_name(nil, f.at(ns("./title")) || @i18n.foreword, s,
55
56
  { class: "ForewordTitle" })
56
57
  f.elements.each { |e| parse(e, s) unless e.name == "title" }
57
58
  end
59
+ @foreword = false
58
60
  end
59
61
  end
60
62
  end
@@ -19,8 +19,11 @@ module IsoDoc
19
19
  f.path
20
20
  end
21
21
  FileUtils.rm_rf dir
22
- MnConvert.convert(in_fname, out_fname || "#{filename}.#{@suffix}",
23
- MnConvert::InputFormat::MN)
22
+ MnConvert.convert(in_fname,
23
+ {
24
+ input_format: MnConvert::InputFormat::MN,
25
+ output_file: out_fname || "#{filename}.#{@suffix}",
26
+ })
24
27
  end
25
28
  end
26
29
  end
@@ -0,0 +1,94 @@
1
+ module IsoDoc
2
+ module Iso
3
+ class WordConvert < IsoDoc::WordConvert
4
+ def figure_cleanup(xml)
5
+ super
6
+ xml.xpath("//div[@class = 'figure']//table[@class = 'dl']").each do |t|
7
+ t["class"] = "figdl"
8
+ d = t.add_previous_sibling("<div class='figdl' "\
9
+ "style='page-break-after:avoid;'/>")
10
+ t.parent = d.first
11
+ end
12
+ end
13
+
14
+ # force Annex h2 down to be p.h2Annex, so it is not picked up by ToC
15
+ def word_annex_cleanup1(docxml, lvl)
16
+ docxml.xpath("//h#{lvl}[ancestor::*[@class = 'Section3']]").each do |h2|
17
+ h2.name = "p"
18
+ h2["class"] = "h#{lvl}Annex"
19
+ end
20
+ end
21
+
22
+ def word_annex_cleanup(docxml)
23
+ (2..6).each { |i| word_annex_cleanup1(docxml, i) }
24
+ end
25
+
26
+ def word_annex_cleanup_h1(docxml)
27
+ docxml.xpath("//h1[@class = 'Annex']").each do |h|
28
+ h.name = "p"
29
+ h["class"] = "ANNEX"
30
+ end
31
+ %w(BiblioTitle ForewordTitle IntroTitle).each do |s|
32
+ docxml.xpath("//*[@class = '#{s}']").each do |h|
33
+ h.name = "p"
34
+ end
35
+ end
36
+ end
37
+
38
+ def style_cleanup(docxml)
39
+ word_annex_cleanup_h1(docxml)
40
+ style_cleanup1(docxml)
41
+ end
42
+
43
+ def style_cleanup1(docxml)
44
+ docxml.xpath("//*[@class = 'example']").each do |p|
45
+ p["class"] = "Example"
46
+ end
47
+ end
48
+
49
+ def authority_hdr_cleanup(docxml)
50
+ docxml&.xpath("//div[@class = 'boilerplate-license']")&.each do |d|
51
+ d.xpath(".//h1").each do |p|
52
+ p.name = "p"
53
+ p["class"] = "zzWarningHdr"
54
+ end
55
+ end
56
+ docxml&.xpath("//div[@class = 'boilerplate-copyright']")&.each do |d|
57
+ d.xpath(".//h1").each do |p|
58
+ p.name = "p"
59
+ p["class"] = "zzCopyrightHdr"
60
+ end
61
+ end
62
+ end
63
+
64
+ def authority_cleanup(docxml)
65
+ insert = docxml.at("//div[@id = 'boilerplate-license-destination']")
66
+ auth = docxml&.at("//div[@class = 'boilerplate-license']")&.remove
67
+ auth&.xpath(".//p[not(@class)]")&.each { |p| p["class"] = "zzWarning" }
68
+ auth and insert.children = auth
69
+ insert = docxml.at("//div[@id = 'boilerplate-copyright-destination']")
70
+ auth = docxml&.at("//div[@class = 'boilerplate-copyright']")&.remove
71
+ auth&.xpath(".//p[not(@class)]")&.each do |p|
72
+ p["class"] = "zzCopyright"
73
+ end
74
+ auth&.xpath(".//p[@id = 'boilerplate-message']")&.each do |p|
75
+ p["class"] = "zzCopyright1"
76
+ end
77
+ auth&.xpath(".//p[@id = 'boilerplate-address']")&.each do |p|
78
+ p["class"] = "zzAddress"
79
+ end
80
+ auth&.xpath(".//p[@id = 'boilerplate-place']")&.each do |p|
81
+ p["class"] = "zzCopyright1"
82
+ end
83
+ auth and insert.children = auth
84
+ end
85
+
86
+ def word_cleanup(docxml)
87
+ authority_hdr_cleanup(docxml)
88
+ super
89
+ style_cleanup(docxml)
90
+ docxml
91
+ end
92
+ end
93
+ end
94
+ end
@@ -1,6 +1,7 @@
1
1
  require_relative "base_convert"
2
2
  require "isodoc"
3
3
  require_relative "init"
4
+ require_relative "word_cleanup"
4
5
 
5
6
  module IsoDoc
6
7
  module Iso
@@ -59,92 +60,11 @@ module IsoDoc
59
60
  return if !stage.nil? && stage < 60
60
61
 
61
62
  body.br **{ clear: "all", style: "page-break-before:left;"\
62
- "mso-break-type:section-break" }
63
+ "mso-break-type:section-break" }
63
64
  body.div **{ class: "colophon" } do |div|
64
65
  end
65
66
  end
66
67
 
67
- def figure_cleanup(xml)
68
- super
69
- xml.xpath("//div[@class = 'figure']//table[@class = 'dl']").each do |t|
70
- t["class"] = "figdl"
71
- d = t.add_previous_sibling("<div class='figdl' "\
72
- "style='page-break-after:avoid;'/>")
73
- t.parent = d.first
74
- end
75
- end
76
-
77
- # force Annex h2 down to be p.h2Annex, so it is not picked up by ToC
78
- def word_annex_cleanup1(docxml, lvl)
79
- docxml.xpath("//h#{lvl}[ancestor::*[@class = 'Section3']]").each do |h2|
80
- h2.name = "p"
81
- h2["class"] = "h#{lvl}Annex"
82
- end
83
- end
84
-
85
- def word_annex_cleanup(docxml)
86
- (2..6).each { |i| word_annex_cleanup1(docxml, i) }
87
- end
88
-
89
- def word_annex_cleanup_h1(docxml)
90
- docxml.xpath("//h1[@class = 'Annex']").each do |h|
91
- h.name = "p"
92
- h["class"] = "ANNEX"
93
- end
94
- %w(BiblioTitle ForewordTitle IntroTitle).each do |s|
95
- docxml.xpath("//*[@class = '#{s}']").each do |h|
96
- h.name = "p"
97
- end
98
- end
99
- end
100
-
101
- def style_cleanup(docxml)
102
- word_annex_cleanup_h1(docxml)
103
- style_cleanup1(docxml)
104
- end
105
-
106
- def style_cleanup1(docxml)
107
- docxml.xpath("//*[@class = 'example']").each do |p|
108
- p["class"] = "Example"
109
- end
110
- end
111
-
112
- def authority_hdr_cleanup(docxml)
113
- docxml&.xpath("//div[@class = 'boilerplate-license']")&.each do |d|
114
- d.xpath(".//h1").each do |p|
115
- p.name = "p"
116
- p["class"] = "zzWarningHdr"
117
- end
118
- end
119
- docxml&.xpath("//div[@class = 'boilerplate-copyright']")&.each do |d|
120
- d.xpath(".//h1").each do |p|
121
- p.name = "p"
122
- p["class"] = "zzCopyrightHdr"
123
- end
124
- end
125
- end
126
-
127
- def authority_cleanup(docxml)
128
- insert = docxml.at("//div[@id = 'boilerplate-license-destination']")
129
- auth = docxml&.at("//div[@class = 'boilerplate-license']")&.remove
130
- auth&.xpath(".//p[not(@class)]")&.each { |p| p["class"] = "zzWarning" }
131
- auth and insert.children = auth
132
- insert = docxml.at("//div[@id = 'boilerplate-copyright-destination']")
133
- auth = docxml&.at("//div[@class = 'boilerplate-copyright']")&.remove
134
- auth&.xpath(".//p[not(@class)]")&.each { |p| p["class"] = "zzCopyright" }
135
- auth&.xpath(".//p[@id = 'boilerplate-message']")&.each { |p| p["class"] = "zzCopyright1" }
136
- auth&.xpath(".//p[@id = 'boilerplate-address']")&.each { |p| p["class"] = "zzAddress" }
137
- auth&.xpath(".//p[@id = 'boilerplate-place']")&.each { |p| p["class"] = "zzCopyright1" }
138
- auth and insert.children = auth
139
- end
140
-
141
- def word_cleanup(docxml)
142
- authority_hdr_cleanup(docxml)
143
- super
144
- style_cleanup(docxml)
145
- docxml
146
- end
147
-
148
68
  def word_toc_preface(level)
149
69
  <<~TOC.freeze
150
70
  <span lang="EN-GB"><span
@@ -166,7 +86,7 @@ module IsoDoc
166
86
  end
167
87
 
168
88
  def bibliography(xml, out)
169
- f = xml.at(ns(bibliography_xpath)) and f["hidden"] != "true" or return
89
+ (f = xml.at(ns(bibliography_xpath)) and f["hidden"] != "true") or return
170
90
  page_break(out)
171
91
  out.div do |div|
172
92
  div.h1 **bibliography_attrs do |h1|
@@ -185,13 +105,16 @@ module IsoDoc
185
105
  end
186
106
  end
187
107
 
108
+ def definition_parse(node, out)
109
+ @definition = true
110
+ super
111
+ @definition = false
112
+ end
113
+
188
114
  def para_class(node)
189
- if !node.ancestors("definition").empty? && !@in_footnote
190
- "Definition"
191
- elsif !node.ancestors("foreword").empty? && !@in_footnote
192
- "ForewordText"
193
- else
194
- super
115
+ if @definition && !@in_footnote then "Definition"
116
+ elsif @foreword && !@in_footnote then "ForewordText"
117
+ else super
195
118
  end
196
119
  end
197
120
 
@@ -201,9 +124,7 @@ module IsoDoc
201
124
 
202
125
  def termref_parse(node, out)
203
126
  out.p **termref_attrs do |p|
204
- p << "[TERMREF]"
205
127
  node.children.each { |n| parse(n, p) }
206
- p << "[/TERMREF]"
207
128
  end
208
129
  end
209
130
 
@@ -4,7 +4,7 @@ module Metanorma
4
4
  module Iso
5
5
  class Processor < Metanorma::Processor
6
6
 
7
- def initialize
7
+ def initialize # rubocop:disable Lint/MissingSuper
8
8
  @short = :iso
9
9
  @input_format = :asciidoc
10
10
  @asciidoctor_backend = :iso
@@ -17,7 +17,7 @@ module Metanorma
17
17
  doc: "doc",
18
18
  pdf: "pdf",
19
19
  sts: "sts.xml",
20
- isosts: "iso.sts.xml"
20
+ isosts: "iso.sts.xml",
21
21
  )
22
22
  end
23
23
 
@@ -1,5 +1,5 @@
1
1
  module Metanorma
2
2
  module ISO
3
- VERSION = "1.10.0".freeze
3
+ VERSION = "1.10.4".freeze
4
4
  end
5
5
  end
@@ -30,16 +30,16 @@ Gem::Specification.new do |spec|
30
30
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
31
31
 
32
32
  spec.add_dependency "metanorma-standoc", "~> 1.11.0"
33
- spec.add_dependency "mnconvert", "~> 1.8.0"
33
+ spec.add_dependency "mnconvert", "~> 2.0"
34
34
  spec.add_dependency "ruby-jing"
35
35
  spec.add_dependency "tokenizer", "~> 0.3.0"
36
36
  spec.add_dependency "twitter_cldr"
37
37
 
38
- spec.add_development_dependency "byebug"
38
+ spec.add_development_dependency "debug"
39
39
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
40
40
  spec.add_development_dependency "guard", "~> 2.14"
41
41
  spec.add_development_dependency "guard-rspec", "~> 4.7"
42
- spec.add_development_dependency "iev", "~> 0.2.0"
42
+ spec.add_development_dependency "iev", "~> 0.3.0"
43
43
  spec.add_development_dependency "rake", "~> 13.0"
44
44
  spec.add_development_dependency "rspec", "~> 3.6"
45
45
  spec.add_development_dependency "rubocop", "~> 1.5.2"