isodoc 0.9.12 → 0.9.13

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: a6c03a961d5e4f165ec88b0cadd23ce527a11dc362321fa1b0f3a13dd85661ba
4
- data.tar.gz: 1e3dea00b58de59aa785fa6b62d3edceb73f6be39989dfce81ab89760b53bd96
3
+ metadata.gz: 945e78a0cc8b1efc187b862f368b0ce1290e613bb6fda7a66c66aac003c7431d
4
+ data.tar.gz: 59f446c8cd4d8e2a82292c22d154de3dcd9f398086f9f33f8455a2dc62f027b9
5
5
  SHA512:
6
- metadata.gz: cab6416eca981238438c32ec69ae6b184bd57402b2083d7d38c72e7ff44f1789132955ae5549624e1851ed86d60318bccd064068cb05c918e69579ac2ed65433
7
- data.tar.gz: 35e405f5e62583960fe5d55b1b4d961290bf64629126b9b56ab3053c5799afa0278d7ddd73f249c91a58100fe8945db4f09720d03bed961b2f9da206dc51be77
6
+ metadata.gz: 8bddacabfb2f52f3200d338b7c7fae3f5497df524a87e49fe7623785dd9acd468ac78d77b62e968c090ef40b12f7faae92a67367326e06c7c66ef2aa4217b09f
7
+ data.tar.gz: 6d70b11d7058cfa38d9d467853003e3ccf994591969c81f38092490aa2e1399e1a2e091e2b1738e1cf89e62163916fa9b8d3be94c0c2595d8c099987764dd16b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- isodoc (0.9.12)
4
+ isodoc (0.9.13)
5
5
  asciimath
6
6
  html2doc (~> 0.8.6)
7
7
  htmlentities (~> 4.3.4)
@@ -67,10 +67,10 @@ GEM
67
67
  mime-types (3.2.2)
68
68
  mime-types-data (~> 3.2015)
69
69
  mime-types-data (3.2018.0812)
70
- mini_portile2 (2.3.0)
70
+ mini_portile2 (2.4.0)
71
71
  nenv (0.3.0)
72
- nokogiri (1.8.5)
73
- mini_portile2 (~> 2.3.0)
72
+ nokogiri (1.9.1)
73
+ mini_portile2 (~> 2.4.0)
74
74
  notiffany (0.1.1)
75
75
  nenv (~> 0.1)
76
76
  shellany (~> 0.0)
@@ -84,8 +84,8 @@ GEM
84
84
  rainbow (3.0.0)
85
85
  rake (12.3.2)
86
86
  rb-fsevent (0.10.3)
87
- rb-inotify (0.9.10)
88
- ffi (>= 0.5.0, < 2)
87
+ rb-inotify (0.10.0)
88
+ ffi (~> 1.0)
89
89
  roman-numerals (0.3.0)
90
90
  rspec (3.8.0)
91
91
  rspec-core (~> 3.8.0)
@@ -146,4 +146,4 @@ DEPENDENCIES
146
146
  timecop (~> 0.9)
147
147
 
148
148
  BUNDLED WITH
149
- 1.17.1
149
+ 1.17.2
@@ -42,11 +42,13 @@ module IsoDoc::Function
42
42
  def get_linkend(node)
43
43
  link = anchor_linkend(node, docid_l10n(node["target"] || node["citeas"]))
44
44
  link += eref_localities(node.xpath(ns("./locality")), link)
45
- text = node.children.select { |c| c.text? && !c.text.empty? }
46
- link = text.join(" ") unless text.nil? || text.empty?
45
+ #text = node.children.select { |c| c.text? && !c.text.empty? }
46
+ #link = text.join(" ") unless text.nil? || text.empty?
47
+ contents = node.children.select { |c| c.name != "locality" }
48
+ return link if contents.nil? || contents.empty?
49
+ Nokogiri::XML::NodeSet.new(node.document, contents).to_xml
47
50
  # so not <origin bibitemid="ISO7301" citeas="ISO 7301">
48
51
  # <locality type="section"><reference>3.1</reference></locality></origin>
49
- link
50
52
  end
51
53
 
52
54
  def xref_parse(node, out)
@@ -43,7 +43,8 @@ module IsoDoc::Function
43
43
  out.div **{ class: "Note" } do |div|
44
44
  first = node.first_element_child
45
45
  div.p do |p|
46
- p << "#{get_anchors[node['id']][:label]}: "
46
+ anchor = get_anchors[node['id']]
47
+ p << "#{anchor&.dig(:label) || '???'}: "
47
48
  para_then_remainder(first, node, p, div)
48
49
  end
49
50
  end
@@ -117,14 +117,16 @@ module IsoDoc::Function
117
117
 
118
118
  def smallcap_parse(node, xml)
119
119
  xml.span **{ style: "font-variant:small-caps;" } do |s|
120
- s << node.inner_html
120
+ #s << node.inner_html
121
+ node.children.each { |n| parse(n, s) }
121
122
  end
122
123
  end
123
124
 
124
125
  def text_parse(node, out)
125
126
  return if node.nil? || node.text.nil?
126
127
  text = node.to_s
127
- text = text.gsub("\n", "<br/>").gsub(" ", "&nbsp;") if in_sourcecode
128
+ text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/>&nbsp;").
129
+ gsub(/[ ](?=[ ])/, "&nbsp;") if in_sourcecode
128
130
  out << text
129
131
  end
130
132
 
@@ -134,7 +136,44 @@ module IsoDoc::Function
134
136
 
135
137
  def keyword_parse(node, out)
136
138
  out.span **{ class: "keyword" } do |s|
137
- s << node.inner_html
139
+ #s << node.inner_html
140
+ node.children.each { |n| parse(n, s) }
141
+ end
142
+ end
143
+
144
+ def em_parse(node, out)
145
+ out.i do |e|
146
+ node.children.each { |n| parse(n, e) }
147
+ end
148
+ end
149
+
150
+ def strong_parse(node, out)
151
+ out.b do |e|
152
+ node.children.each { |n| parse(n, e) }
153
+ end
154
+ end
155
+
156
+ def sup_parse(node, out)
157
+ out.sup do |e|
158
+ node.children.each { |n| parse(n, e) }
159
+ end
160
+ end
161
+
162
+ def sub_parse(node, out)
163
+ out.sub do |e|
164
+ node.children.each { |n| parse(n, e) }
165
+ end
166
+ end
167
+
168
+ def tt_parse(node, out)
169
+ out.tt do |e|
170
+ node.children.each { |n| parse(n, e) }
171
+ end
172
+ end
173
+
174
+ def strike_parse(node, out)
175
+ out.s do |e|
176
+ node.children.each { |n| parse(n, e) }
138
177
  end
139
178
  end
140
179
 
@@ -143,12 +182,18 @@ module IsoDoc::Function
143
182
  text_parse(node, out)
144
183
  else
145
184
  case node.name
146
- when "em" then out.i { |e| e << node.inner_html }
147
- when "strong" then out.b { |e| e << node.inner_html }
148
- when "sup" then out.sup { |e| e << node.inner_html }
149
- when "sub" then out.sub { |e| e << node.inner_html }
150
- when "tt" then out.tt { |e| e << node.inner_html }
151
- when "strike" then out.s { |e| e << node.inner_html }
185
+ #when "em" then out.i { |e| e << node.inner_html }
186
+ #when "strong" then out.b { |e| e << node.inner_html }
187
+ #when "sup" then out.sup { |e| e << node.inner_html }
188
+ #when "sub" then out.sub { |e| e << node.inner_html }
189
+ #when "tt" then out.tt { |e| e << node.inner_html }
190
+ #when "strike" then out.s { |e| e << node.inner_html }
191
+ when "em" then em_parse(node, out)
192
+ when "strong" then strong_parse(node, out)
193
+ when "sup" then sup_parse(node, out)
194
+ when "sub" then sub_parse(node, out)
195
+ when "tt" then tt_parse(node, out)
196
+ when "strike" then strike_parse(node, out)
152
197
  when "keyword" then keyword_parse(node, out)
153
198
  when "smallcap" then smallcap_parse(node, out)
154
199
  when "br" then out.br
@@ -158,7 +203,6 @@ module IsoDoc::Function
158
203
  when "callout" then callout_parse(node, out)
159
204
  when "stem" then stem_parse(node, out)
160
205
  when "clause" then clause_parse(node, out)
161
- # when "subclause" then clause_parse(node, out)
162
206
  #when "appendix" then clause_parse(node, out)
163
207
  when "xref" then xref_parse(node, out)
164
208
  when "eref" then eref_parse(node, out)
@@ -10,7 +10,7 @@ module IsoDoc::Function
10
10
  end
11
11
 
12
12
  def initial_anchor_names(d)
13
- preface_names(d.at(ns("//abstract")))
13
+ preface_names(d.at(ns("//preface/abstract")))
14
14
  preface_names(d.at(ns("//foreword")))
15
15
  preface_names(d.at(ns("//introduction")))
16
16
  sequential_asset_names(d.xpath(ns("//preface/abstract | //foreword | //introduction")))
@@ -1,3 +1,3 @@
1
1
  module IsoDoc
2
- VERSION = "0.9.12".freeze
2
+ VERSION = "0.9.13".freeze
3
3
  end
@@ -1,6 +1,8 @@
1
1
  module IsoDoc::WordFunction
2
2
  module Body
3
3
  def make_body1(body, _docxml)
4
+ FileUtils.rm_rf tmpimagedir
5
+ FileUtils.mkdir tmpimagedir
4
6
  body.div **{ class: "WordSection1" } do |div1|
5
7
  div1.p { |p| p << "&nbsp;" } # placeholder
6
8
  end
@@ -172,7 +174,8 @@ module IsoDoc::WordFunction
172
174
  out.div **{ class: "Note" } do |div|
173
175
  first = node.first_element_child
174
176
  div.p **{ class: "Note" } do |p|
175
- p << "#{get_anchors[node['id']][:label]}: "
177
+ anchor = get_anchors[node['id']]
178
+ p << "#{anchor&.dig(:label) || '???'}: "
176
179
  para_then_remainder(first, node, p, div)
177
180
  end
178
181
  end
@@ -191,8 +194,19 @@ module IsoDoc::WordFunction
191
194
  attrs
192
195
  end
193
196
 
197
+ def imgsrc(uri)
198
+ return uri unless %r{^data:image/}.match uri
199
+ %r{^data:image/(?<imgtype>[^;]+);base64,(?<imgdata>.+)$} =~ uri
200
+ uuid = UUIDTools::UUID.random_create.to_s
201
+ fname = "#{uuid}.#{imgtype}"
202
+ new_file = File.join(tmpimagedir, fname)
203
+ @files_to_delete << new_file
204
+ File.open(new_file, "wb") { |f| f.write(Base64.strict_decode64(imgdata)) }
205
+ File.join(rel_tmpimagedir, fname)
206
+ end
207
+
194
208
  def image_parse(node, out, caption)
195
- attrs = { src: node["src"],
209
+ attrs = { src: imgsrc(node["src"]),
196
210
  height: node["height"],
197
211
  width: node["width"] }
198
212
  if node["height"] == "auto" || node["width"] == "auto"
@@ -206,7 +220,7 @@ module IsoDoc::WordFunction
206
220
  def xref_parse(node, out)
207
221
  target = /#/.match(node["target"]) ? node["target"].sub(/#/, ".doc#") :
208
222
  "##{node["target"]}"
209
- out.a(**{ "href": target }) { |l| l << get_linkend(node) }
223
+ out.a(**{ "href": target }) { |l| l << get_linkend(node) }
210
224
  end
211
225
  end
212
226
  end
@@ -230,6 +230,7 @@ INPUT
230
230
  <name>Split-it-right <em>sample</em> divider</name>
231
231
  <image src="rice_images/rice_image1.png" height="20" width="30" id="_8357ede4-6d44-4672-bac4-9a85e82ab7f0" imagetype="PNG"/>
232
232
  <image src="rice_images/rice_image1.png" height="20" width="auto" id="_8357ede4-6d44-4672-bac4-9a85e82ab7f0" imagetype="PNG"/>
233
+ <image src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7" height="20" width="auto" id="_8357ede4-6d44-4672-bac4-9a85e82ab7f0" imagetype="PNG"/>
233
234
  <fn reference="a">
234
235
  <p id="_ef2c85b8-5a5a-4ecd-a1e6-92acefaaa852">The time <stem type="AsciiMath">t_90</stem> was estimated to be 18,2 min for this example.</p>
235
236
  </fn>
@@ -253,6 +254,7 @@ B</pre>
253
254
 
254
255
  <img src="rice_images/rice_image1.png" height="20" width="30"/>
255
256
  <img src="rice_images/rice_image1.png" height="20" width="auto"/>
257
+ <img src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7" height="20" width="auto"/>
256
258
  <a href="#_" class="TableFootnoteRef">a</a><aside class="footnote"><div id="fn:_"><a id="_" class="TableFootnoteRef">a&#160; </a>
257
259
  <p id="_">The time <span class="stem">(#(t_90)#)</span> was estimated to be 18,2 min for this example.</p>
258
260
  </div></aside>
@@ -278,6 +280,7 @@ B</pre>
278
280
  <name>Split-it-right sample divider</name>
279
281
  <image src="rice_images/rice_image1.png" height="20" width="30" id="_8357ede4-6d44-4672-bac4-9a85e82ab7f0" imagetype="PNG"/>
280
282
  <image src="rice_images/rice_image1.png" height="20" width="auto" id="_8357ede4-6d44-4672-bac4-9a85e82ab7f0" imagetype="PNG"/>
283
+ <image src="data:image/gif;base64,R0lGODlhEAAQAMQAAORHHOVSKudfOulrSOp3WOyDZu6QdvCchPGolfO0o/XBs/fNwfjZ0frl3/zy7////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAkAABAALAAAAAAQABAAAAVVICSOZGlCQAosJ6mu7fiyZeKqNKToQGDsM8hBADgUXoGAiqhSvp5QAnQKGIgUhwFUYLCVDFCrKUE1lBavAViFIDlTImbKC5Gm2hB0SlBCBMQiB0UjIQA7" height="20" width="auto" id="_8357ede4-6d44-4672-bac4-9a85e82ab7f0" imagetype="PNG"/>
281
284
  <fn reference="a">
282
285
  <p id="_ef2c85b8-5a5a-4ecd-a1e6-92acefaaa852">The time <stem type="AsciiMath">t_90</stem> was estimated to be 18,2 min for this example.</p>
283
286
  </fn>
@@ -308,6 +311,7 @@ B</pre>
308
311
 
309
312
  <img src="rice_images/rice_image1.png" height="20" width="30"/>
310
313
  <img src="rice_images/rice_image1.png"/>
314
+ <img src="test_images/_.gif"/>
311
315
  <a href="#_" class="TableFootnoteRef">a</a><aside><div id="ftn_"><a id="_" class="TableFootnoteRef">a<span style="mso-tab-count:1">&#160; </span></a>
312
316
  <p id="_">The time <span class="stem">(#(t_90)#)</span> was estimated to be 18,2 min for this example.</p>
313
317
  </div></aside>
@@ -416,7 +420,7 @@ B</pre>
416
420
  <br/>
417
421
  <div>
418
422
  <h1 class="ForewordTitle">Foreword</h1>
419
- <p id="samplecode" class="Sourcecode"><br/>&#160;&#160;&#160;&#160;<br/>&#160;&#160;puts&#160;x<br/><p class="FigureTitle" align="center">Ruby <i>code</i></p></p>
423
+ <p id="samplecode" class="Sourcecode"><br/>&#160;&#160;&#160; <br/>&#160; puts x<br/><p class="FigureTitle" align="center">Ruby <i>code</i></p></p>
420
424
  </div>
421
425
  <p class="zzSTDTitle1"/>
422
426
  </div>
@@ -440,7 +444,7 @@ B</pre>
440
444
  <br/>
441
445
  <div>
442
446
  <h1 class="ForewordTitle">Foreword</h1>
443
- <p id="samplecode" class="Sourcecode"><br/>&#160;&#160;&#160;&#160;<br/>&#160;&#160;&lt;xml&gt;<br/><p class="FigureTitle" align="center">XML code</p></p>
447
+ <p id="samplecode" class="Sourcecode"><br/>&#160;&#160;&#160; <br/>&#160; &lt;xml&gt;<br/><p class="FigureTitle" align="center">XML code</p></p>
444
448
  </div>
445
449
  <p class="zzSTDTitle1"/>
446
450
  </div>
@@ -468,7 +472,7 @@ B</pre>
468
472
  <br/>
469
473
  <div>
470
474
  <h1 class="ForewordTitle">Foreword</h1>
471
- <p id="_" class="Sourcecode">puts&#160;"Hello,&#160;world."&#160; &lt;1&gt;<br/>&#160;&#160;&#160;%w{a&#160;b&#160;c}.each&#160;do&#160;|x|<br/>&#160;&#160;&#160;&#160;&#160;puts&#160;x&#160; &lt;2&gt;<br/>&#160;&#160;&#160;end<span class="zzMoveToFollowing">&lt;1&gt; </span>
475
+ <p id="_" class="Sourcecode">puts "Hello, world." &lt;1&gt;<br/>&#160;&#160; %w{a b c}.each do |x|<br/>&#160;&#160;&#160;&#160; puts x &lt;2&gt;<br/>&#160;&#160; end<span class="zzMoveToFollowing">&lt;1&gt; </span>
472
476
  <p class="Sourcecode" id="_">This is one callout</p>
473
477
  <span class="zzMoveToFollowing">&lt;2&gt; </span>
474
478
  <p class="Sourcecode" id="_">This is another callout</p>
@@ -31,6 +31,32 @@ RSpec.describe IsoDoc do
31
31
  OUTPUT
32
32
  end
33
33
 
34
+ it "processes embedded inline formatting" do
35
+ expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
36
+ <iso-standard xmlns="http://riboseinc.com/isoxml">
37
+ <preface><foreword>
38
+ <p>
39
+ <em><strong>&lt;</strong></em> <tt><link target="B"/></tt> <xref target="_http_1_1">Requirement <tt>/req/core/http</tt></xref> <eref type="inline" bibitemid="ISO712" citeas="ISO 712">Requirement <tt>/req/core/http</tt></eref> <eref type="inline" bibitemid="ISO712" citeas="ISO 712"><locality type="section"><referenceFrom>3.1</referenceFrom></locality></eref>
40
+ </p>
41
+ </foreword></preface>
42
+ <sections>
43
+ </iso-standard>
44
+ INPUT
45
+ #{HTML_HDR}
46
+ <br/>
47
+ <div>
48
+ <h1 class="ForewordTitle">Foreword</h1>
49
+ <p>
50
+ <i><b>&lt;</b></i> <tt><a href="B">B</a></tt> <a href="#_http_1_1">Requirement <tt>/req/core/http</tt></a> <a href="#ISO712">Requirement <tt>/req/core/http</tt></a> <a href="#ISO712">ISO 712, Section 3.1</a>
51
+ </p>
52
+ </div>
53
+ <p class="zzSTDTitle1"/>
54
+ </div>
55
+ </body>
56
+ </html>
57
+ OUTPUT
58
+ end
59
+
34
60
  it "processes links" do
35
61
  expect(IsoDoc::HtmlConvert.new({}).convert("test", <<~"INPUT", true)).to be_equivalent_to <<~"OUTPUT"
36
62
  <iso-standard xmlns="http://riboseinc.com/isoxml">
data/spec/spec_helper.rb CHANGED
@@ -25,7 +25,8 @@ def strip_guid(x)
25
25
  gsub(%r( href="#[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{13}"), ' href="#_"').
26
26
  gsub(%r( id="[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{13}"), ' id="_"').
27
27
  gsub(%r( id="ftn[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{13}"), ' id="ftn_"').
28
- gsub(%r( id="fn:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{13}"), ' id="fn:_"')
28
+ gsub(%r( id="fn:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{13}"), ' id="fn:_"').
29
+ gsub(%r[ src="([^/]+)/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.], ' src="\\1/_.')
29
30
  end
30
31
 
31
32
  HTML_HDR = <<~END
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isodoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.12
4
+ version: 0.9.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-11 00:00:00.000000000 Z
11
+ date: 2018-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciimath