isodoc 1.8.0 → 1.8.1

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: e798df14fbf858fd0540d3fb2837774ec6a1924d5590ad4a628699888eff8425
4
- data.tar.gz: 8f3e143a4c3cbcba0c4c349c315c6bf7b067164cd4cc22bd06a85dce71268e73
3
+ metadata.gz: ec504b3b905ec960bef74398b3789ab5b7eb248dc05a7c3f64590db77d31cac6
4
+ data.tar.gz: c2de4c1589a7ff282715f4930a1851393358a64fd407c5a1e3bda02beddc0782
5
5
  SHA512:
6
- metadata.gz: 6a0fbbabc25df62e19eeefecbf3369188194e28348ac6758f59024b58c0e4e23695440e41263c049455a12b1ce210e602c58e6142e9b8b95ac79d2fa8a64d341
7
- data.tar.gz: 888429742fbf4ee0ab902b1a34d5edb8d7657b2fb561ecf3fe872fe48de14267e0e7edcae1e27c86ed5b36dc8d0becccd0ca6f96f6f1239936fb1bd287dc0130
6
+ metadata.gz: 34a1c43f6f34f90aa326ed7ff50ede791eadaf22c05ebf0f4183fb2cb3c708bd4f0512572b638a94e236b807f5a873986c24579fe126eb88ad15ef1e178c64d2
7
+ data.tar.gz: 23fbe4f295729ad565ab787903e9c4b49388671766b91477dc3d26302b8499da892f77d6e034ce4f6cc4ba1b0956c8dbb051e94a3a336acdb661d1e6d30e584b
@@ -119,6 +119,7 @@ module IsoDoc
119
119
 
120
120
  def convert1(docxml, filename, dir)
121
121
  @xrefs.parse docxml
122
+ bibitem_lookup(docxml)
122
123
  noko do |xml|
123
124
  xml.html **{ lang: @lang.to_s } do |html|
124
125
  html.parent.add_namespace("epub", "http://www.idpf.org/2007/ops")
@@ -130,6 +131,13 @@ module IsoDoc
130
131
  end.join("\n")
131
132
  end
132
133
 
134
+ def bibitem_lookup(docxml)
135
+ @bibitems = docxml.xpath(ns("//references/bibitem"))
136
+ .each_with_object({}) do |b, m|
137
+ m[b["id"]] = b
138
+ end
139
+ end
140
+
133
141
  def metadata_init(lang, script, i18n)
134
142
  @meta = Metadata.new(lang, script, i18n)
135
143
  end
@@ -41,10 +41,8 @@ module IsoDoc
41
41
  end
42
42
 
43
43
  def eref_target(node)
44
- href = "##{node['bibitemid']}"
45
- url = node.at(ns("//bibitem[@id = '#{node['bibitemid']}']/"\
46
- "uri[@type = 'citation']"))
47
- return href unless url
44
+ return "##{node['bibitemid']}" unless url = @bibitems[node["bibitemid"]]
45
+ &.at(ns("./uri[@type = 'citation']"))
48
46
 
49
47
  href = suffix_url(url.text)
50
48
  anchor = node&.at(ns(".//locality[@type = 'anchor']"))&.text&.strip
@@ -5,6 +5,7 @@ module IsoDoc
5
5
  module HtmlFunction
6
6
  module Html
7
7
  def convert1(docxml, filename, dir)
8
+ bibitem_lookup(docxml)
8
9
  noko do |xml|
9
10
  xml.html **{ lang: @lang.to_s } do |html|
10
11
  info docxml, nil
@@ -1,5 +1,6 @@
1
1
  require "isodoc/html_function/mathvariant_to_plain"
2
2
  require_relative "postprocess_footnotes"
3
+ require "metanorma-utils"
3
4
 
4
5
  module IsoDoc
5
6
  module HtmlFunction
@@ -74,7 +75,8 @@ module IsoDoc
74
75
  head = docxml.at("//*[local-name() = 'head']")
75
76
  head << htmlstylesheet(@htmlstylesheet)
76
77
  s = htmlstylesheet(@htmlstylesheet_override) and head << s
77
- @bare and head << "<style>body {margin-left: 2em; margin-right: 2em;}</style>"
78
+ @bare and
79
+ head << "<style>body {margin-left: 2em; margin-right: 2em;}</style>"
78
80
  docxml
79
81
  end
80
82
 
@@ -167,11 +169,7 @@ module IsoDoc
167
169
  end
168
170
 
169
171
  def datauri(img)
170
- type = img["src"].split(".")[-1]
171
- supertype = type == "xml" ? "application" : "image"
172
- bin = IO.binread(image_localfile(img))
173
- data = Base64.strict_encode64(bin)
174
- img["src"] = "data:#{supertype}/#{type};base64,#{data}"
172
+ img["src"] = Metanorma::Utils::datauri(img["src"], @localdir)
175
173
  end
176
174
 
177
175
  def image_suffix(img)
@@ -6,7 +6,7 @@ module IsoDoc
6
6
  vote-ended}.freeze
7
7
 
8
8
  def months
9
- {
9
+ {
10
10
  "01": @labels["month_january"],
11
11
  "02": @labels["month_february"],
12
12
  "03": @labels["month_march"],
@@ -19,30 +19,32 @@ module IsoDoc
19
19
  "10": @labels["month_october"],
20
20
  "11": @labels["month_november"],
21
21
  "12": @labels["month_december"],
22
- }
22
+ }
23
23
  end
24
24
 
25
25
  def monthyr(isodate)
26
26
  m = /(?<yr>\d\d\d\d)-(?<mo>\d\d)/.match isodate
27
27
  return isodate unless m && m[:yr] && m[:mo]
28
+
28
29
  l10n("#{months[m[:mo].to_sym]} #{m[:yr]}",
29
- @lang, @script)
30
+ @lang, @script)
30
31
  end
31
32
 
32
33
  def MMMddyyyy(isodate)
33
34
  return nil if isodate.nil?
35
+
34
36
  arr = isodate.split("-")
35
- date = if arr.size == 1 and (/^\d+$/.match isodate)
36
- Date.new(*arr.map(&:to_i)).strftime("%Y")
37
- elsif arr.size == 2
38
- Date.new(*arr.map(&:to_i)).strftime("%B %Y")
39
- else
40
- Date.parse(isodate).strftime("%B %d, %Y")
41
- end
37
+ if arr.size == 1 && (/^\d+$/.match isodate)
38
+ Date.new(*arr.map(&:to_i)).strftime("%Y")
39
+ elsif arr.size == 2
40
+ Date.new(*arr.map(&:to_i)).strftime("%B %Y")
41
+ else
42
+ Date.parse(isodate).strftime("%B %d, %Y")
43
+ end
42
44
  end
43
45
 
44
46
  def bibdate(isoxml, _out)
45
- isoxml.xpath(ns('//bibdata/date')).each do |d|
47
+ isoxml.xpath(ns("//bibdata/date")).each do |d|
46
48
  set("#{d['type'].gsub(/-/, '_')}date".to_sym, Common::date_range(d))
47
49
  end
48
50
  end
@@ -10,7 +10,7 @@ module IsoDoc
10
10
  "</localized-strings>"
11
11
  end
12
12
 
13
- def docid_prefixes(docxml)
13
+ def docid_prefixes(docxml)
14
14
  docxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
15
15
  i.children = @xrefs.klass.docid_prefix(i["type"], i.text)
16
16
  end
@@ -97,7 +97,7 @@ module IsoDoc
97
97
 
98
98
  # https://stackoverflow.com/a/31822406
99
99
  def blank?(elem)
100
- elem.nil? || elem.respond_to?(:empty?) && elem.empty?
100
+ elem.nil? || (elem.respond_to?(:empty?) && elem.empty?)
101
101
  end
102
102
 
103
103
  def trim_hash(hash)
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "1.8.0".freeze
2
+ VERSION = "1.8.1".freeze
3
3
  end
@@ -54,11 +54,11 @@ module IsoDoc
54
54
  end
55
55
 
56
56
  def para_class(_node)
57
- classtype = nil
58
- classtype = "Note" if @note
59
- classtype = "MsoCommentText" if in_comment
60
- classtype = "Sourcecode" if @annotation
61
- classtype
57
+ return "Sourcecode" if @annotation
58
+ return "MsoCommentText" if @in_comment
59
+ return "Note" if @note
60
+
61
+ nil
62
62
  end
63
63
 
64
64
  def para_parse(node, out)
@@ -86,21 +86,31 @@ module IsoDoc
86
86
  end
87
87
 
88
88
  def dl_parse(node, out)
89
+ return super unless node.ancestors("table, dl").empty?
90
+
91
+ dl_parse_table(node, out)
92
+ end
93
+
94
+ def dl_parse_table(node, out)
89
95
  out.table **{ class: "dl" } do |v|
90
96
  node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
91
- v.tr do |tr|
92
- tr.td **{ valign: "top", align: "left" } do |term|
93
- dt_parse(dt, term)
94
- end
95
- tr.td **{ valign: "top" } do |listitem|
96
- dd.children.each { |n| parse(n, listitem) }
97
- end
98
- end
97
+ dl_parse_table1(v, dt, dd)
99
98
  end
100
99
  dl_parse_notes(node, v)
101
100
  end
102
101
  end
103
102
 
103
+ def dl_parse_table1(table, dterm, ddefn)
104
+ table.tr do |tr|
105
+ tr.td **{ valign: "top", align: "left" } do |term|
106
+ dt_parse(dterm, term)
107
+ end
108
+ tr.td **{ valign: "top" } do |listitem|
109
+ ddefn.children.each { |n| parse(n, listitem) }
110
+ end
111
+ end
112
+ end
113
+
104
114
  def dl_parse_notes(node, out)
105
115
  return if node.elements.reject { |n| dt_dd? n }.empty?
106
116
 
@@ -120,8 +130,8 @@ module IsoDoc
120
130
  dl
121
131
  end
122
132
 
133
+ # get rid of footnote link, it is in diagram
123
134
  def figure_aside_process(fig, aside, key)
124
- # get rid of footnote link, it is in diagram
125
135
  fig&.at("./a[@class='TableFootnoteRef']")&.remove
126
136
  fnref = fig.at(".//span[@class='TableFootnoteRef']/..")
127
137
  tr = key.add_child("<tr></tr>").first
@@ -1,10 +1,6 @@
1
1
  module IsoDoc
2
2
  module WordFunction
3
3
  module Comments
4
- def in_comment
5
- @in_comment
6
- end
7
-
8
4
  def comments(div)
9
5
  return if @comments.empty?
10
6
 
@@ -7,6 +7,10 @@ module IsoDoc
7
7
  recommendation permission figure table formula
8
8
  admonition sourcecode).freeze
9
9
 
10
+ def blank?(text)
11
+ text.nil? || text.empty?
12
+ end
13
+
10
14
  def amend_preprocess(xmldoc)
11
15
  xmldoc.xpath(ns("//amend[newcontent]")).each do |a|
12
16
  autonum = amend_autonums(a)
@@ -39,11 +43,9 @@ module IsoDoc
39
43
  end
40
44
 
41
45
  def termnote_anchor_names(docxml)
42
- docxml.xpath(ns("//term[descendant::termnote]")).each do |t|
46
+ docxml.xpath(ns("//term[termnote]")).each do |t|
43
47
  c = Counter.new
44
- t.xpath(ns(".//termnote")).each do |n|
45
- next if n["id"].nil? || n["id"].empty?
46
-
48
+ t.xpath(ns("./termnote")).reject { |n| blank?(n["id"]) }.each do |n|
47
49
  c.increment(n)
48
50
  @anchors[n["id"]] =
49
51
  { label: termnote_label(c.print), type: "termnote", value: c.print,
@@ -54,18 +56,18 @@ module IsoDoc
54
56
  end
55
57
 
56
58
  def termexample_anchor_names(docxml)
57
- docxml.xpath(ns("//term[descendant::termexample]")).each do |t|
58
- examples = t.xpath(ns(".//termexample"))
59
+ docxml.xpath(ns("//term[termexample]")).each do |t|
60
+ examples = t.xpath(ns("./termexample"))
59
61
  c = Counter.new
60
- examples.each do |n|
61
- next if n["id"].nil? || n["id"].empty?
62
-
62
+ examples.reject { |n| blank?(n["id"]) }.each do |n|
63
63
  c.increment(n)
64
64
  idx = increment_label(examples, n, c, false)
65
65
  @anchors[n["id"]] =
66
- { type: "termexample", label: idx, value: c.print,
67
- xref: l10n("#{anchor(t['id'], :xref)}, "\
68
- "#{@labels['example_xref']} #{c.print}") }
66
+ # { type: "termexample", label: idx, value: c.print,
67
+ # xref: l10n("#{anchor(t['id'], :xref)}, "\
68
+ # "#{@labels['example_xref']} #{c.print}") }
69
+ anchor_struct(idx, n,
70
+ @labels["example_xref"], "termexample", n["unnumbered"])
69
71
  end
70
72
  end
71
73
  end
@@ -127,9 +129,7 @@ module IsoDoc
127
129
  notes = s.xpath(ns(".//ol")) - s.xpath(ns(".//clause//ol")) -
128
130
  s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol"))
129
131
  c = Counter.new
130
- notes.each do |n|
131
- next if n["id"].nil? || n["id"].empty?
132
-
132
+ notes.reject { |n| blank?(n["id"]) }.each do |n|
133
133
  @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
134
134
  @labels["list"], "list", false)
135
135
  list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1)
@@ -158,9 +158,7 @@ module IsoDoc
158
158
  notes = s.xpath(ns(".//dl")) - s.xpath(ns(".//clause//dl")) -
159
159
  s.xpath(ns(".//appendix//dl")) - s.xpath(ns(".//dl//dl"))
160
160
  c = Counter.new
161
- notes.each do |n|
162
- next if n["id"].nil? || n["id"].empty?
163
-
161
+ notes.reject { |n| blank?(n["id"]) }.each do |n|
164
162
  @anchors[n["id"]] =
165
163
  anchor_struct(increment_label(notes, n, c), n,
166
164
  @labels["deflist"], "deflist", false)
@@ -183,10 +181,8 @@ module IsoDoc
183
181
  end
184
182
  end
185
183
 
186
- def bookmark_anchor_names(docxml)
187
- docxml.xpath(ns(".//bookmark")).each do |n|
188
- next if n["id"].nil? || n["id"].empty?
189
-
184
+ def bookmark_anchor_names(xml)
185
+ xml.xpath(ns(".//bookmark")).reject { |n| blank?(n["id"]) }.each do |n|
190
186
  parent = nil
191
187
  n.ancestors.each do |a|
192
188
  next unless a["id"] && parent = @anchors.dig(a["id"], :xref)
@@ -34,8 +34,7 @@ module IsoDoc::XrefGen
34
34
 
35
35
  def sequential_table_names(clause)
36
36
  c = Counter.new
37
- clause.xpath(ns(".//table")).each do |t|
38
- next if t["id"].nil? || t["id"].empty?
37
+ clause.xpath(ns(".//table")).reject { |n| blank?(n["id"]) }.each do |t|
39
38
 
40
39
  @anchors[t["id"]] = anchor_struct(
41
40
  c.increment(t).print, nil,
@@ -46,8 +45,7 @@ module IsoDoc::XrefGen
46
45
 
47
46
  def sequential_formula_names(clause)
48
47
  c = Counter.new
49
- clause.xpath(ns(".//formula")).each do |t|
50
- next if t["id"].nil? || t["id"].empty?
48
+ clause.xpath(ns(".//formula")).reject { |n| blank?(n["id"]) }.each do |t|
51
49
 
52
50
  @anchors[t["id"]] = anchor_struct(
53
51
  c.increment(t).print, t,
@@ -62,8 +60,8 @@ module IsoDoc::XrefGen
62
60
 
63
61
  def sequential_permission_names(clause, klass, label)
64
62
  c = Counter.new
65
- clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")).each do |t|
66
- next if t["id"].nil? || t["id"].empty?
63
+ clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}"))
64
+ .reject { |n| blank?(n["id"]) }.each do |t|
67
65
 
68
66
  id = c.increment(t).print
69
67
  @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"])
@@ -82,8 +80,7 @@ module IsoDoc::XrefGen
82
80
 
83
81
  def sequential_permission_names1(block, lbl, klass, label)
84
82
  c = Counter.new
85
- block.xpath(ns("./#{klass}")).each do |t|
86
- next if t["id"].nil? || t["id"].empty?
83
+ block.xpath(ns("./#{klass}")).reject { |n| blank?(n["id"]) }.each do |t|
87
84
 
88
85
  id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
89
86
  @anchors[t["id"]] = anchor_struct(id, t, label, klass, t["unnumbered"])
@@ -118,8 +115,7 @@ module IsoDoc::XrefGen
118
115
 
119
116
  def hierarchical_table_names(clause, num)
120
117
  c = Counter.new
121
- clause.xpath(ns(".//table")).each do |t|
122
- next if t["id"].nil? || t["id"].empty?
118
+ clause.xpath(ns(".//table")).reject { |n| blank?(n["id"]) }.each do |t|
123
119
 
124
120
  @anchors[t["id"]] =
125
121
  anchor_struct("#{num}#{hiersep}#{c.increment(t).print}",
@@ -141,8 +137,7 @@ module IsoDoc::XrefGen
141
137
 
142
138
  def hierarchical_formula_names(clause, num)
143
139
  c = Counter.new
144
- clause.xpath(ns(".//formula")).each do |t|
145
- next if t["id"].nil? || t["id"].empty?
140
+ clause.xpath(ns(".//formula")).reject { |n| blank?(n["id"]) }.each do |t|
146
141
 
147
142
  @anchors[t["id"]] = anchor_struct(
148
143
  "#{num}#{hiersep}#{c.increment(t).print}", nil,
@@ -154,8 +149,8 @@ module IsoDoc::XrefGen
154
149
 
155
150
  def hierarchical_permission_names(clause, num, klass, label)
156
151
  c = Counter.new
157
- clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}")).each do |t|
158
- next if t["id"].nil? || t["id"].empty?
152
+ clause.xpath(ns(".//#{klass}#{FIRST_LVL_REQ}"))
153
+ .reject { |n| blank?(n["id"]) }.each do |t|
159
154
 
160
155
  id = "#{num}#{hiersep}#{c.increment(t).print}"
161
156
  @anchors[t["id"]] =
@@ -175,8 +170,7 @@ module IsoDoc::XrefGen
175
170
 
176
171
  def hierarchical_permission_names1(block, lbl, klass, label)
177
172
  c = Counter.new
178
- block.xpath(ns("./#{klass}")).each do |t|
179
- next if t["id"].nil? || t["id"].empty?
173
+ block.xpath(ns("./#{klass}")).reject { |n| blank?(n["id"]) }.each do |t|
180
174
 
181
175
  id = "#{lbl}#{hierfigsep}#{c.increment(t).print}"
182
176
  @anchors[t["id"]] =
@@ -809,8 +809,11 @@ RSpec.describe IsoDoc do
809
809
  expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
810
810
  .convert("test", input, true)
811
811
  .gsub(/&lt;/, "&#x3c;")
812
- .gsub(%r{data:application/x-msmetafile[^"']+}, 'data:application/x-msmetafile')
813
- )).to be_equivalent_to xmlpp(presxml.gsub(%r{data:application/x-msmetafile[^"']+}, 'data:application/x-msmetafile'))
812
+ .gsub(%r{data:application/x-msmetafile[^"']+},
813
+ "data:application/x-msmetafile")))
814
+ .to be_equivalent_to xmlpp(presxml
815
+ .gsub(%r{data:application/x-msmetafile[^"']+},
816
+ "data:application/x-msmetafile"))
814
817
  expect(xmlpp(strip_guid(IsoDoc::HtmlConvert.new({})
815
818
  .convert("test", presxml, true)))).to be_equivalent_to xmlpp(html)
816
819
  expect(xmlpp(strip_guid(IsoDoc::WordConvert.new({})
@@ -900,9 +903,11 @@ RSpec.describe IsoDoc do
900
903
  expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
901
904
  .convert("test", input, true)
902
905
  .gsub(/&lt;/, "&#x3c;")
903
- .gsub(%r{data:application/x-msmetafile[^"']+}, 'data:application/x-msmetafile')))
906
+ .gsub(%r{data:application/x-msmetafile[^"']+},
907
+ "data:application/x-msmetafile")))
904
908
  .to be_equivalent_to xmlpp(presxml
905
- .gsub( %r{data:application/x-msmetafile[^"']+}, 'data:application/x-msmetafile'))
909
+ .gsub(%r{data:application/x-msmetafile[^"']+},
910
+ "data:application/x-msmetafile"))
906
911
  expect(xmlpp(strip_guid(IsoDoc::WordConvert.new({})
907
912
  .convert("test", presxml, true)
908
913
  .gsub(/['"][^'".]+(?<!odf1)(?<!odf)\.emf['"]/, "'_.emf'")
@@ -991,9 +996,11 @@ RSpec.describe IsoDoc do
991
996
  expect(xmlpp(IsoDoc::PresentationXMLConvert.new({})
992
997
  .convert("test", input, true)
993
998
  .gsub(/&lt;/, "&#x3c;")
994
- .gsub(%r{data:application/x-msmetafile[^"']+}, 'data:application/x-msmetafile')))
999
+ .gsub(%r{data:application/x-msmetafile[^"']+},
1000
+ "data:application/x-msmetafile")))
995
1001
  .to be_equivalent_to xmlpp(presxml
996
- .gsub( %r{data:application/x-msmetafile[^"']+}, 'data:application/x-msmetafile'))
1002
+ .gsub(%r{data:application/x-msmetafile[^"']+},
1003
+ "data:application/x-msmetafile"))
997
1004
  expect(xmlpp(strip_guid(IsoDoc::WordConvert.new({})
998
1005
  .convert("test", presxml, true)
999
1006
  .gsub(/['"][^'".]+(?<!odf1)(?<!odf)\.svg['"]/, "'_.svg'")
@@ -2521,8 +2528,7 @@ RSpec.describe IsoDoc do
2521
2528
  .convert("test", input, true))
2522
2529
  .sub(%r{<localized-strings>.*</localized-strings>}m, "")
2523
2530
  .gsub(%r{"\.\\}, '"./')
2524
- .gsub(%r{'\.\\}, "'./")
2525
- )
2531
+ .gsub(%r{'\.\\}, "'./"))
2526
2532
  .to be_equivalent_to xmlpp(output)
2527
2533
  end
2528
2534