isodoc 2.1.5 → 2.2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/isodoc.gemspec +5 -5
  3. data/lib/isodoc/class_utils.rb +1 -4
  4. data/lib/isodoc/convert.rb +56 -42
  5. data/lib/isodoc/function/inline.rb +12 -7
  6. data/lib/isodoc/function/references.rb +1 -1
  7. data/lib/isodoc/function/reqt.rb +17 -88
  8. data/lib/isodoc/function/section_titles.rb +3 -3
  9. data/lib/isodoc/function/table.rb +1 -1
  10. data/lib/isodoc/function/to_word_html.rb +7 -6
  11. data/lib/isodoc/function/utils.rb +4 -0
  12. data/lib/isodoc/init.rb +20 -0
  13. data/lib/isodoc/presentation_function/block.rb +23 -6
  14. data/lib/isodoc/presentation_function/image.rb +68 -19
  15. data/lib/isodoc/presentation_function/refs.rb +102 -0
  16. data/lib/isodoc/presentation_function/section.rb +1 -80
  17. data/lib/isodoc/presentation_function/terms.rb +9 -13
  18. data/lib/isodoc/presentation_xml_convert.rb +1 -0
  19. data/lib/isodoc/version.rb +1 -1
  20. data/lib/isodoc/word_function/postprocess.rb +1 -1
  21. data/lib/isodoc/xref/xref_counter.rb +12 -0
  22. data/lib/isodoc/xref/xref_gen.rb +17 -5
  23. data/lib/isodoc/xref/xref_gen_seq.rb +106 -81
  24. data/lib/isodoc/xref.rb +6 -0
  25. data/lib/isodoc-yaml/i18n-ar.yaml +0 -2
  26. data/lib/isodoc-yaml/i18n-de.yaml +0 -2
  27. data/lib/isodoc-yaml/i18n-en.yaml +9 -2
  28. data/lib/isodoc-yaml/i18n-es.yaml +0 -2
  29. data/lib/isodoc-yaml/i18n-fr.yaml +0 -2
  30. data/lib/isodoc-yaml/i18n-ru.yaml +0 -2
  31. data/lib/isodoc-yaml/i18n-zh-Hans.yaml +0 -2
  32. data/lib/relaton/render/general.rb +1 -18
  33. metadata +34 -26
  34. data/lib/isodoc/base_style/all.css +0 -227
  35. data/lib/isodoc/base_style/blocks.css +0 -0
  36. data/lib/isodoc/base_style/coverpage.css +0 -0
  37. data/lib/isodoc/base_style/defaults.css +0 -0
  38. data/lib/isodoc/base_style/metanorma_word.css +0 -47
  39. data/lib/isodoc/base_style/nav.css +0 -0
  40. data/lib/isodoc/base_style/reset.css +0 -125
  41. data/lib/isodoc/base_style/typography.css +0 -0
@@ -11,7 +11,14 @@ module IsoDoc
11
11
  else s.remove
12
12
  end
13
13
  end
14
- docxml.xpath(ns("//image")).each { |f| svg_emf_double(f) }
14
+ imageconvert(docxml)
15
+ end
16
+
17
+ def imageconvert(docxml)
18
+ docxml.xpath(ns("//image")).each do |f|
19
+ eps2svg(f)
20
+ svg_emf_double(f)
21
+ end
15
22
  end
16
23
 
17
24
  def svg_extract(elem)
@@ -36,6 +43,16 @@ module IsoDoc
36
43
  l10n("#{lower2cap @i18n.figure} #{lbl}"), "name")
37
44
  end
38
45
 
46
+ def eps2svg(img)
47
+ return unless eps?(img["mimetype"])
48
+
49
+ img["mimetype"] = "image/svg+xml"
50
+ if src = eps_to_svg(img)
51
+ img["src"] = src
52
+ img.children = ""
53
+ end
54
+ end
55
+
39
56
  def svg_emf_double(img)
40
57
  if emf?(img["mimetype"])
41
58
  img = emf_encode(img)
@@ -46,40 +63,59 @@ module IsoDoc
46
63
  end
47
64
 
48
65
  def emf_encode(img)
49
- img["mimetype"] = "image/svg+xml"
50
- unless %r{^data:image}.match?(img["src"])
51
- img["src"] = Metanorma::Utils::datauri(img["src"])
52
- end
66
+ svg_prep(img)
53
67
  img.children = "<emf src='#{img['src']}'/>"
54
68
  img["src"] = ""
55
69
  img
56
70
  end
57
71
 
72
+ def svg_prep(img)
73
+ img["mimetype"] = "image/svg+xml"
74
+ %r{^data:image}.match?(img["src"]) or
75
+ img["src"] = Metanorma::Utils::datauri(img["src"])
76
+ end
77
+
58
78
  def emf_to_svg(img)
59
79
  emf = Metanorma::Utils::save_dataimage(img.at(ns("./emf/@src")).text)
60
80
  Emf2svg.from_file(emf).sub(/<\?[^>]+>/, "")
61
81
  end
62
82
 
83
+ def eps_to_svg(node)
84
+ uri = eps_to_svg_uri(node)
85
+ ret = imgfile_suffix(uri, "svg")
86
+ File.exist?(ret) and return ret
87
+ inkscape_convert(uri, ret, "--export-plain-svg")
88
+ end
89
+
63
90
  def svg_to_emf(node)
64
91
  uri = svg_to_emf_uri(node)
65
- ret = svg_to_emf_filename(uri)
92
+ ret = imgfile_suffix(uri, "emf")
66
93
  File.exist?(ret) and return ret
94
+ inkscape_convert(uri, ret, '--export-type="emf"')
95
+ end
96
+
97
+ def inkscape_convert(uri, file, option)
67
98
  exe = inkscape_installed? or raise "Inkscape missing in PATH, unable" \
68
- "to convert EMF to SVG. Aborting."
99
+ "to convert image #{uri}. Aborting."
69
100
  uri = Metanorma::Utils::external_path uri
70
101
  exe = Metanorma::Utils::external_path exe
71
- system(%(#{exe} --export-type="emf" #{uri})) and
72
- return Metanorma::Utils::datauri(ret)
102
+ system(%(#{exe} #{option} #{uri})) and
103
+ return Metanorma::Utils::datauri(file)
73
104
 
74
- raise %(Fail on #{exe} --export-type="emf" #{uri})
105
+ raise %(Fail on #{exe} #{option} #{uri})
75
106
  end
76
107
 
77
108
  def svg_to_emf_uri(node)
78
- uri = if node&.elements&.first&.name == "svg"
79
- a = Base64.strict_encode64(node.children.to_xml)
80
- "data:image/svg+xml;base64,#{a}"
81
- else node["src"]
82
- end
109
+ uri = svg_to_emf_uri_convert(node)
110
+ cache_dataimage(uri)
111
+ end
112
+
113
+ def eps_to_svg_uri(node)
114
+ uri = eps_to_svg_uri_convert(node)
115
+ cache_dataimage(uri)
116
+ end
117
+
118
+ def cache_dataimage(uri)
83
119
  if %r{^data:}.match?(uri)
84
120
  uri = save_dataimage(uri)
85
121
  @tempfile_cache << uri
@@ -87,12 +123,25 @@ module IsoDoc
87
123
  uri
88
124
  end
89
125
 
90
- def svg_to_emf_filename(uri)
91
- "#{File.join(File.dirname(uri), File.basename(uri, '.*'))}.emf"
126
+ def svg_to_emf_uri_convert(node)
127
+ if node&.elements&.first&.name == "svg"
128
+ a = Base64.strict_encode64(node.children.to_xml)
129
+ "data:image/svg+xml;base64,#{a}"
130
+ else node["src"]
131
+ end
132
+ end
133
+
134
+ def eps_to_svg_uri_convert(node)
135
+ if node.text.strip.empty?
136
+ node["src"]
137
+ else
138
+ a = Base64.strict_encode64(node.children.to_xml)
139
+ "data:application/postscript;base64,#{a}"
140
+ end
92
141
  end
93
142
 
94
- def emf_to_svgfilename(uri)
95
- "#{File.join(File.dirname(uri), File.basename(uri, '.*'))}.svg"
143
+ def imgfile_suffix(uri, suffix)
144
+ "#{File.join(File.dirname(uri), File.basename(uri, '.*'))}.#{suffix}"
96
145
  end
97
146
 
98
147
  def inkscape_installed?
@@ -0,0 +1,102 @@
1
+ require_relative "../../relaton/render/general"
2
+
3
+ module IsoDoc
4
+ class PresentationXMLConvert < ::IsoDoc::Convert
5
+ def references(docxml)
6
+ bibliography_bibitem_number(docxml)
7
+ renderings = references_render(docxml)
8
+ docxml.xpath(ns("//references/bibitem")).each do |x|
9
+ bibitem(x, renderings)
10
+ end
11
+ docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
12
+ x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
13
+ x["hidden"] = "true"
14
+ end
15
+ @xrefs.parse_inclusions(refs: true).parse(docxml)
16
+ end
17
+
18
+ def references_render(docxml)
19
+ d = docxml.clone
20
+ d.remove_namespaces!
21
+ refs = d.xpath("//references/bibitem").each_with_object([]) do |b, m|
22
+ prep_for_rendering(b)
23
+ m << b.to_xml
24
+ end.join
25
+ bibrenderer.render_all("<references>#{refs}</references>",
26
+ type: citestyle)
27
+ end
28
+
29
+ def prep_for_rendering(bib)
30
+ bib["suppress_identifier"] == true and
31
+ bib.xpath(ns("./docidentifier")).each(&:remove)
32
+ bib["type"] ||= "standard"
33
+ end
34
+
35
+ def bibitem(xml, renderings)
36
+ @xrefs.klass.implicit_reference(xml) and xml["hidden"] = "true"
37
+ bibrender(xml, renderings)
38
+ end
39
+
40
+ def bibrender(xml, renderings)
41
+ if f = xml.at(ns("./formattedref"))
42
+ bibrender_formattedref(f, xml)
43
+ else bibrender_relaton(xml, renderings)
44
+ end
45
+ end
46
+
47
+ def bibrender_formattedref(formattedref, xml)
48
+ code = render_identifier(bibitem_ref_code(xml))
49
+ (code[:sdo] && xml["suppress_identifier"] != "true") and
50
+ formattedref << " [#{code[:sdo]}] "
51
+ end
52
+
53
+ def bibrender_relaton(xml, renderings)
54
+ f = renderings[xml["id"]][:formattedref]
55
+ f &&= "<formattedref>#{f}</formattedref>"
56
+ xml.children =
57
+ "#{f}#{xml.xpath(ns('./docidentifier | ./uri | ./note')).to_xml}"
58
+ end
59
+
60
+ def bibrenderer
61
+ ::Relaton::Render::IsoDoc::General.new(language: @lang)
62
+ end
63
+
64
+ def citestyle
65
+ nil
66
+ end
67
+
68
+ def bibliography_bibitem_number_skip(bibitem)
69
+ @xrefs.klass.implicit_reference(bibitem) ||
70
+ bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) ||
71
+ bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
72
+ bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
73
+ end
74
+
75
+ def bibliography_bibitem_number(docxml)
76
+ i = 0
77
+ docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
78
+ i = bibliography_bibitem_number1(b, i)
79
+ end
80
+ @xrefs.references docxml
81
+ end
82
+
83
+ def bibliography_bibitem_number1(bibitem, idx)
84
+ ins = bibitem.at(ns(".//docidentifier")).previous_element
85
+ mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) and
86
+ /^\[?\d+\]?$/.match?(mn.text) and
87
+ mn.remove # ignore numbers already inserted
88
+ unless bibliography_bibitem_number_skip(bibitem)
89
+ idx += 1
90
+ ins.next =
91
+ "<docidentifier type='metanorma-ordinal'>[#{idx}]</docidentifier>"
92
+ end
93
+ idx
94
+ end
95
+
96
+ def docid_prefixes(docxml)
97
+ docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
98
+ i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,4 +1,4 @@
1
- require_relative "../../relaton/render/general"
1
+ require_relative "refs"
2
2
 
3
3
  module IsoDoc
4
4
  class PresentationXMLConvert < ::IsoDoc::Convert
@@ -76,85 +76,6 @@ module IsoDoc
76
76
  prefix_name(elem, "", "#{lbl}#{clausedelim}", "name")
77
77
  end
78
78
 
79
- def references(docxml)
80
- bibliography_bibitem_number(docxml)
81
- docxml.xpath(ns("//references/bibitem")).each do |x|
82
- bibitem(x)
83
- end
84
- docxml.xpath(ns("//references[bibitem/@hidden = 'true']")).each do |x|
85
- x.at(ns("./bibitem[not(@hidden = 'true')]")) and next
86
- x["hidden"] = "true"
87
- end
88
- @xrefs.parse_inclusions(refs: true).parse(docxml)
89
- end
90
-
91
- def bibitem(xml)
92
- @xrefs.klass.implicit_reference(xml) and
93
- xml["hidden"] = "true"
94
- bibrender(xml)
95
- end
96
-
97
- def bibrender(xml)
98
- if f = xml.at(ns("./formattedref"))
99
- bibrender_formattedref(f, xml)
100
- else bibrender_relaton(xml)
101
- end
102
- end
103
-
104
- def bibrender_formattedref(formattedref, xml)
105
- code = render_identifier(bibitem_ref_code(xml))
106
- (code[:sdo] && xml["suppress_identifier"] != "true") and
107
- formattedref << " [#{code[:sdo]}] "
108
- end
109
-
110
- def bibrender_relaton(xml)
111
- bib = xml.dup
112
- bib["suppress_identifier"] == true and
113
- bib.xpath(ns("./docidentifier")).each(&:remove)
114
- xml.children =
115
- "#{bibrenderer.render(bib.to_xml)}"\
116
- "#{xml.xpath(ns('./docidentifier | ./uri | ./note')).to_xml}"
117
- end
118
-
119
- def bibrenderer
120
- ::Relaton::Render::IsoDoc::General.new(language: @lang)
121
- end
122
-
123
- def bibliography_bibitem_number_skip(bibitem)
124
- @xrefs.klass.implicit_reference(bibitem) ||
125
- bibitem.at(ns(".//docidentifier[@type = 'metanorma']")) ||
126
- bibitem.at(ns(".//docidentifier[@type = 'metanorma-ordinal']")) ||
127
- bibitem["hidden"] == "true" || bibitem.parent["hidden"] == "true"
128
- end
129
-
130
- def bibliography_bibitem_number(docxml)
131
- i = 0
132
- docxml.xpath(ns("//references[@normative = 'false']/bibitem")).each do |b|
133
- i = bibliography_bibitem_number1(b, i)
134
- end
135
- @xrefs.references docxml
136
- end
137
-
138
- def bibliography_bibitem_number1(bibitem, idx)
139
- if mn = bibitem.at(ns(".//docidentifier[@type = 'metanorma']"))
140
- /^\[?\d\]?$/.match?(mn&.text) and
141
- idx = mn.text.sub(/^\[/, "").sub(/\]$/, "").to_i
142
- end
143
- unless bibliography_bibitem_number_skip(bibitem)
144
-
145
- idx += 1
146
- bibitem.at(ns(".//docidentifier")).previous =
147
- "<docidentifier type='metanorma-ordinal'>[#{idx}]</docidentifier>"
148
- end
149
- idx
150
- end
151
-
152
- def docid_prefixes(docxml)
153
- docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
154
- i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
155
- end
156
- end
157
-
158
79
  def index(docxml)
159
80
  docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove)
160
81
  end
@@ -28,10 +28,9 @@ module IsoDoc
28
28
  end
29
29
 
30
30
  def concept1_nonital(node, opts)
31
- if opts[:ital] == "false"
32
- r = node.at(ns(".//renderterm"))
33
- r&.replace(r&.children)
34
- end
31
+ opts[:ital] == "false" or return
32
+ r = node.at(ns(".//renderterm"))
33
+ r&.replace(r&.children)
35
34
  end
36
35
 
37
36
  def concept_render_init(node, defaults)
@@ -43,11 +42,11 @@ module IsoDoc
43
42
  end
44
43
 
45
44
  def concept1_linkmention(ref, renderterm, opts)
46
- if opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?
47
- ref2 = ref.clone
48
- r2 = renderterm.clone
49
- renderterm.replace(ref2).children = r2
50
- end
45
+ return unless opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?
46
+
47
+ ref2 = ref.clone
48
+ r2 = renderterm.clone
49
+ renderterm.replace(ref2).children = r2
51
50
  end
52
51
 
53
52
  def concept1_ref(_node, ref, opts)
@@ -92,9 +91,7 @@ module IsoDoc
92
91
  end
93
92
 
94
93
  def designation(docxml)
95
- docxml.xpath(ns("//term")).each do |t|
96
- merge_second_preferred(t)
97
- end
94
+ docxml.xpath(ns("//term")).each { |t| merge_second_preferred(t) }
98
95
  docxml.xpath(ns("//preferred | //admitted | //deprecates")).each do |p|
99
96
  designation1(p)
100
97
  end
@@ -194,7 +191,6 @@ module IsoDoc
194
191
  end
195
192
  end
196
193
 
197
- # introduce name element
198
194
  def termnote1(elem)
199
195
  lbl = l10n(@xrefs.anchor(elem["id"], :label) || "???")
200
196
  prefix_name(elem, "", lower2cap(lbl), "name")
@@ -59,6 +59,7 @@ module IsoDoc
59
59
  permission docxml
60
60
  requirement docxml
61
61
  recommendation docxml
62
+ requirement_render docxml
62
63
  end
63
64
 
64
65
  def inline(docxml)
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "2.1.5".freeze
2
+ VERSION = "2.2.2.2".freeze
3
3
  end
@@ -98,7 +98,7 @@ module IsoDoc
98
98
  docxml.xpath("//p[@class='Biblio']//span[@style='mso-tab-count:1']")
99
99
  .each do |s|
100
100
  s.next.text? or next
101
- s.next.replace(s.next.text.sub(/^\s+/, ""))
101
+ s.next.replace(@c.encode(s.next.text.sub(/^\s+/, ""), :hexadecimal))
102
102
  end
103
103
  end
104
104
 
@@ -2,6 +2,18 @@ require "roman-numerals"
2
2
 
3
3
  module IsoDoc
4
4
  module XrefGen
5
+ class ReqCounter
6
+ # one counter for each requirements label
7
+ def initialize
8
+ @counters = {}
9
+ end
10
+
11
+ def increment(label, node)
12
+ @counters[label] ||= Counter.new
13
+ @counters[label].increment(node)
14
+ end
15
+ end
16
+
5
17
  class Counter
6
18
  def initialize(num = 0, opts = { numerals: :arabic })
7
19
  @unnumbered = false
@@ -1,5 +1,13 @@
1
1
  require_relative "xref_gen_seq"
2
2
 
3
+ module Enumerable
4
+ def noblank
5
+ reject do |n|
6
+ n["id"].nil? || n["id"].empty?
7
+ end
8
+ end
9
+ end
10
+
3
11
  module IsoDoc
4
12
  module XrefGen
5
13
  module Blocks
@@ -11,6 +19,10 @@ module IsoDoc
11
19
  text.nil? || text.empty?
12
20
  end
13
21
 
22
+ def noblank(xpath)
23
+ xpath.reject { |n| blank?(n["id"]) }
24
+ end
25
+
14
26
  def amend_preprocess(xmldoc)
15
27
  xmldoc.xpath(ns("//amend[newcontent]")).each do |a|
16
28
  autonum = amend_autonums(a)
@@ -45,7 +57,7 @@ module IsoDoc
45
57
  def termnote_anchor_names(docxml)
46
58
  docxml.xpath(ns("//*[termnote]")).each do |t|
47
59
  c = Counter.new
48
- t.xpath(ns("./termnote")).reject { |n| blank?(n["id"]) }.each do |n|
60
+ t.xpath(ns("./termnote")).noblank.each do |n|
49
61
  c.increment(n)
50
62
  @anchors[n["id"]] =
51
63
  { label: termnote_label(c.print), type: "termnote",
@@ -60,7 +72,7 @@ module IsoDoc
60
72
  docxml.xpath(ns("//*[termexample]")).each do |t|
61
73
  examples = t.xpath(ns("./termexample"))
62
74
  c = Counter.new
63
- examples.reject { |n| blank?(n["id"]) }.each do |n|
75
+ examples.noblank.each do |n|
64
76
  c.increment(n)
65
77
  idx = increment_label(examples, n, c, increment: false)
66
78
  @anchors[n["id"]] = anchor_struct(idx, n, @labels["example_xref"],
@@ -135,7 +147,7 @@ module IsoDoc
135
147
  notes = s.xpath(ns(".//ol")) - s.xpath(ns(".//clause//ol")) -
136
148
  s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol"))
137
149
  c = Counter.new
138
- notes.reject { |n| blank?(n["id"]) }.each do |n|
150
+ notes.noblank.each do |n|
139
151
  @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
140
152
  @labels["list"], "list", false)
141
153
  list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1)
@@ -169,7 +181,7 @@ module IsoDoc
169
181
  end
170
182
 
171
183
  def deflist_anchor_names1(notes, counter)
172
- notes.reject { |n| blank?(n["id"]) }.each do |n|
184
+ notes.noblank.each do |n|
173
185
  @anchors[n["id"]] =
174
186
  anchor_struct(increment_label(notes, n, counter), n,
175
187
  @labels["deflist"], "deflist", false)
@@ -197,7 +209,7 @@ module IsoDoc
197
209
  end
198
210
 
199
211
  def bookmark_anchor_names(xml)
200
- xml.xpath(ns(".//bookmark")).reject { |n| blank?(n["id"]) }.each do |n|
212
+ xml.xpath(ns(".//bookmark")).noblank.each do |n|
201
213
  parent = nil
202
214
  n.ancestors.each do |a|
203
215
  next unless a["id"] && parent = @anchors.dig(a["id"], :xref)