reverse_adoc 0.2.3 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/macos.yml +8 -4
  3. data/.github/workflows/ubuntu.yml +10 -4
  4. data/.github/workflows/windows.yml +12 -5
  5. data/Gemfile +3 -1
  6. data/Gemfile.lock +84 -0
  7. data/README.adoc +36 -3
  8. data/bin/reverse_adoc +7 -0
  9. data/bin/w2a +5 -17
  10. data/lib/reverse_asciidoctor.rb +7 -47
  11. data/lib/reverse_asciidoctor/cleaner.rb +23 -0
  12. data/lib/reverse_asciidoctor/config.rb +2 -1
  13. data/lib/reverse_asciidoctor/converters/a.rb +6 -2
  14. data/lib/reverse_asciidoctor/converters/example.rb +17 -0
  15. data/lib/reverse_asciidoctor/converters/express_ref.rb +12 -0
  16. data/lib/reverse_asciidoctor/converters/ext_description.rb +16 -0
  17. data/lib/reverse_asciidoctor/converters/ext_descriptions.rb +12 -0
  18. data/lib/reverse_asciidoctor/converters/h.rb +17 -2
  19. data/lib/reverse_asciidoctor/converters/img.rb +23 -20
  20. data/lib/reverse_asciidoctor/converters/note.rb +17 -0
  21. data/lib/reverse_asciidoctor/html_converter.rb +56 -0
  22. data/lib/reverse_asciidoctor/smrl_description_converter.rb +45 -0
  23. data/lib/reverse_asciidoctor/version.rb +1 -1
  24. data/reverse_adoc.gemspec +1 -0
  25. data/spec/assets/anchors.html +8 -0
  26. data/spec/assets/external_images.docx +0 -0
  27. data/spec/assets/external_images.html +35 -0
  28. data/spec/bin/reverse_adoc_spec.rb +32 -0
  29. data/spec/bin/w2a_spec.rb +35 -0
  30. data/spec/components/anchors_spec.rb +5 -0
  31. data/spec/lib/reverse_asciidoctor/cleaner_spec.rb +24 -0
  32. data/spec/lib/reverse_asciidoctor/converters/example_spec.rb +22 -0
  33. data/spec/lib/reverse_asciidoctor/converters/express_ref_spec.rb +14 -0
  34. data/spec/lib/reverse_asciidoctor/converters/ext_description_spec.rb +20 -0
  35. data/spec/lib/reverse_asciidoctor/converters/ext_descriptions_spec.rb +13 -0
  36. data/spec/lib/reverse_asciidoctor/converters/note_spec.rb +22 -0
  37. data/spec/lib/reverse_asciidoctor_spec.rb +58 -5
  38. data/spec/spec_helper.rb +5 -0
  39. data/spec/support/shell_helpers.rb +15 -0
  40. metadata +45 -3
@@ -18,4 +18,9 @@ describe ReverseAsciidoctor do
18
18
  it { is_expected.to include ' link <<content2>>internal jumplinks without anchors ' }
19
19
  it { is_expected.to include ' treat [[content]] as bookmarks ' }
20
20
 
21
+ it { is_expected.to include "<<a_bspaced,Double \\_\\_ anchor with space>>" }
22
+ it { is_expected.to include "[[a_bspaced]]" }
23
+ it { is_expected.to include "[[a_Foreword]]\n== Text" }
24
+ it { is_expected.not_to include "[[_Toc12345]]" }
25
+
21
26
  end
@@ -3,6 +3,30 @@ require 'spec_helper'
3
3
  describe ReverseAsciidoctor::Cleaner do
4
4
  let(:cleaner) { ReverseAsciidoctor::Cleaner.new }
5
5
 
6
+ describe '#scrub_whitespace' do
7
+ it "makes consistent nonbreaking spaces" do
8
+ result = cleaner.scrub_whitespace("&nbsp; &#xA0;  ")
9
+ expect(result).to eq "&#xA0; &#xA0; &#xA0;"
10
+ end
11
+
12
+ it "makes four linebreaks into two" do
13
+ result = cleaner.scrub_whitespace("A\n\n\n\nB")
14
+ expect(result).to eq "A\n\nB"
15
+ end
16
+ end
17
+
18
+ describe '#clean_headings' do
19
+ it "removes empty headings" do
20
+ result = cleaner.clean_headings("<h2></h2>")
21
+ expect(result).to eq " "
22
+ end
23
+
24
+ it "cleans superscripts rendered as headings" do
25
+ result = cleaner.clean_headings(%{<p class="Standard" style="font-size: 12pt; font-family: Calibri; writing-mode: lr-tb; margin: 0;" align="left ! important"><span class="T1" style="margin: 0;">H</span><h1 class="T2" style="vertical-align: super; font-size: 58%; margin: 0;">2</h1><span class="T1" style="margin: 0;">0</span></p>})
26
+ expect(result).to eq %{<p class="Standard" style="font-size: 12pt; font-family: Calibri; writing-mode: lr-tb; margin: 0;" align="left ! important"><span class="T1" style="margin: 0;">H</span><sup>2</sup><span class="T1" style="margin: 0;">0</span></p>}
27
+ end
28
+ end
29
+
6
30
  describe '#remove_newlines' do
7
31
  it 'removes more than 2 subsequent newlines' do
8
32
  result = cleaner.remove_newlines("foo\n\n\nbar")
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'reverse_asciidoctor/converters/example'
5
+
6
+ describe ReverseAsciidoctor::Converters::Example do
7
+ let(:converter) { described_class.new }
8
+ let(:output) do
9
+ <<~TEXT
10
+ [example]
11
+ ====
12
+ foo
13
+
14
+ ====
15
+ TEXT
16
+ end
17
+
18
+ it 'converts example` children' do
19
+ input = node_for('<example><li>foo</li></example>')
20
+ expect(converter.convert(input)).to eq(output)
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'reverse_asciidoctor/converters/express_ref'
5
+
6
+ describe ReverseAsciidoctor::Converters::ExpressRef do
7
+ let(:converter) { described_class.new }
8
+ let(:schema) { 'schema' }
9
+
10
+ it 'converts supplied tag by format' do
11
+ input = node_for("<express_ref linkend='#{schema}' />")
12
+ expect(converter.convert(input)).to eq("express_ref:[#{schema}]")
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'reverse_asciidoctor/converters/ext_description'
5
+
6
+ describe ReverseAsciidoctor::Converters::ExtDescription do
7
+ let(:converter) { described_class.new }
8
+ let(:schema) { 'schema' }
9
+
10
+ it 'takes ext_description linkend attribute' do
11
+ input = node_for("<ext_description linkend='#{schema}'></ext_description>")
12
+ expect(converter.convert(input)).to include(%{(*"#{schema}"})
13
+ end
14
+
15
+ it 'converts html children' do
16
+ input = node_for(
17
+ "<ext_description linkend='#{schema}'><li>foo</li></ext_description>")
18
+ expect(converter.convert(input)).to include(" foo\n")
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'reverse_asciidoctor/converters/ext_descriptions'
5
+
6
+ describe ReverseAsciidoctor::Converters::ExtDescriptions do
7
+ let(:converter) { described_class.new }
8
+
9
+ it 'converts ext_descriptions children' do
10
+ input = node_for('<ext_descriptions><li>foo</li></ext_descriptions>')
11
+ expect(converter.convert(input)).to eq " foo\n"
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'reverse_asciidoctor/converters/note'
5
+
6
+ describe ReverseAsciidoctor::Converters::Note do
7
+ let(:converter) { described_class.new }
8
+ let(:output) do
9
+ <<~TEXT
10
+ [NOTE]
11
+ --
12
+ foo
13
+
14
+ --
15
+ TEXT
16
+ end
17
+
18
+ it 'converts note` children' do
19
+ input = node_for('<note><li>foo</li></note>')
20
+ expect(converter.convert(input)).to eq(output)
21
+ end
22
+ end
@@ -4,19 +4,19 @@ describe ReverseAsciidoctor do
4
4
  let(:input) { File.read('spec/assets/minimum.html') }
5
5
  let(:document) { Nokogiri::HTML(input) }
6
6
 
7
- it "parses nokogiri documents" do
7
+ it 'parses nokogiri documents' do
8
8
  expect { ReverseAsciidoctor.convert(document) }.not_to raise_error
9
9
  end
10
10
 
11
- it "parses nokogiri elements" do
11
+ it 'parses nokogiri elements' do
12
12
  expect { ReverseAsciidoctor.convert(document.root) }.not_to raise_error
13
13
  end
14
14
 
15
- it "parses string input" do
15
+ it 'parses string input' do
16
16
  expect { ReverseAsciidoctor.convert(input) }.not_to raise_error
17
17
  end
18
18
 
19
- it "behaves in a sane way when root element is nil" do
19
+ it 'behaves in a sane way when root element is nil' do
20
20
  expect(ReverseAsciidoctor.convert(nil)).to eq ''
21
21
  end
22
22
 
@@ -28,10 +28,63 @@ describe ReverseAsciidoctor do
28
28
 
29
29
  it 'can be used as a block configurator as well' do
30
30
  ReverseAsciidoctor.config do |config|
31
- expect(config.tag_border).to eq " "
31
+ expect(config.tag_border).to eq ' '
32
32
  config.tag_border = true
33
33
  end
34
34
  expect(ReverseAsciidoctor.config.tag_border).to eq true
35
35
  end
36
36
  end
37
+
38
+ shared_examples 'converting source with external images included' do |result|
39
+ let(:temp_dir) do
40
+ Pathname.new(ReverseAsciidoctor.config.destination).dirname
41
+ end
42
+ let(:images_folder) { File.join(temp_dir, 'images') }
43
+
44
+ before do
45
+ ReverseAsciidoctor.config.destination = File.join(Dir.mktmpdir,
46
+ 'output.html')
47
+ ReverseAsciidoctor.config.sourcedir = Dir.mktmpdir
48
+ ReverseAsciidoctor.config.external_images = true
49
+ end
50
+
51
+ after do
52
+ FileUtils.rm_rf(temp_dir)
53
+ end
54
+
55
+ it 'Creates local files from external URI' do
56
+ expect { convert }
57
+ .to(change do
58
+ Dir["#{images_folder}/*gif"]
59
+ .map { |entry| File.basename(entry) }
60
+ .sort
61
+ end.from([]).to(result))
62
+ end
63
+ end
64
+
65
+ # TODO: fix github actions integration with libreoffice, currently it hangs
66
+ # when trying to use soffice binary
67
+ unless Gem::Platform.local.os == 'darwin' && !ENV['GITHUB_ACTION'].nil?
68
+ context 'when docx file input' do
69
+ subject(:convert) do
70
+ ReverseAsciidoctor.convert(
71
+ ReverseAsciidoctor.cleaner.preprocess_word_html(input.document.html),
72
+ WordToMarkdown::REVERSE_MARKDOWN_OPTIONS
73
+ )
74
+ end
75
+ let(:input) do
76
+ WordToMarkdown.new('spec/assets/external_images.docx',
77
+ ReverseAsciidoctor.config.sourcedir)
78
+ end
79
+ it_behaves_like 'converting source with external images included',
80
+ ['001.gif', '002.gif']
81
+ end
82
+ end
83
+
84
+ context 'when html file input' do
85
+ subject(:convert) { ReverseAsciidoctor.convert(input) }
86
+ let(:input) { File.read('spec/assets/external_images.html') }
87
+ it_behaves_like 'converting source with external images included',
88
+ ['001.gif']
89
+ end
37
90
  end
@@ -9,6 +9,11 @@ end
9
9
  SimpleCov.start 'gem'
10
10
 
11
11
  require 'reverse_asciidoctor'
12
+ require 'reverse_asciidoctor/html_converter'
13
+ require 'word-to-markdown'
14
+
15
+ Dir[File.join('spec', 'support', '**', '*.rb')]
16
+ .each { |f| require File.join('.', f) }
12
17
 
13
18
  RSpec.configure do |config|
14
19
  config.after(:each) do
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ module ShellUtils
6
+ class ShellExcutionError < StandardError; end
7
+ module_function
8
+
9
+ def execute!(cmd)
10
+ stdout, stderr, status = Open3.capture3(cmd)
11
+ raise(ShellExcutionError, stderr) unless status.success?
12
+
13
+ stdout
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reverse_adoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-07 00:00:00.000000000 Z
11
+ date: 2020-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mimemagic
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -137,6 +151,7 @@ files:
137
151
  - ".hound.yml"
138
152
  - ".rubocop.yml"
139
153
  - Gemfile
154
+ - Gemfile.lock
140
155
  - LICENSE.txt
141
156
  - README.adoc
142
157
  - Rakefile
@@ -157,6 +172,10 @@ files:
157
172
  - lib/reverse_asciidoctor/converters/div.rb
158
173
  - lib/reverse_asciidoctor/converters/drop.rb
159
174
  - lib/reverse_asciidoctor/converters/em.rb
175
+ - lib/reverse_asciidoctor/converters/example.rb
176
+ - lib/reverse_asciidoctor/converters/express_ref.rb
177
+ - lib/reverse_asciidoctor/converters/ext_description.rb
178
+ - lib/reverse_asciidoctor/converters/ext_descriptions.rb
160
179
  - lib/reverse_asciidoctor/converters/figure.rb
161
180
  - lib/reverse_asciidoctor/converters/h.rb
162
181
  - lib/reverse_asciidoctor/converters/head.rb
@@ -166,6 +185,7 @@ files:
166
185
  - lib/reverse_asciidoctor/converters/li.rb
167
186
  - lib/reverse_asciidoctor/converters/mark.rb
168
187
  - lib/reverse_asciidoctor/converters/math.rb
188
+ - lib/reverse_asciidoctor/converters/note.rb
169
189
  - lib/reverse_asciidoctor/converters/ol.rb
170
190
  - lib/reverse_asciidoctor/converters/p.rb
171
191
  - lib/reverse_asciidoctor/converters/pass_through.rb
@@ -181,12 +201,16 @@ files:
181
201
  - lib/reverse_asciidoctor/converters/tr.rb
182
202
  - lib/reverse_asciidoctor/converters/video.rb
183
203
  - lib/reverse_asciidoctor/errors.rb
204
+ - lib/reverse_asciidoctor/html_converter.rb
205
+ - lib/reverse_asciidoctor/smrl_description_converter.rb
184
206
  - lib/reverse_asciidoctor/version.rb
185
207
  - reverse_adoc.gemspec
186
208
  - spec/assets/anchors.html
187
209
  - spec/assets/basic.html
188
210
  - spec/assets/code.html
189
211
  - spec/assets/escapables.html
212
+ - spec/assets/external_images.docx
213
+ - spec/assets/external_images.html
190
214
  - spec/assets/from_the_wild.html
191
215
  - spec/assets/full_example.html
192
216
  - spec/assets/html_fragment.html
@@ -196,6 +220,8 @@ files:
196
220
  - spec/assets/quotation.html
197
221
  - spec/assets/tables.html
198
222
  - spec/assets/unknown_tags.html
223
+ - spec/bin/reverse_adoc_spec.rb
224
+ - spec/bin/w2a_spec.rb
199
225
  - spec/components/anchors_spec.rb
200
226
  - spec/components/basic_spec.rb
201
227
  - spec/components/code_spec.rb
@@ -215,10 +241,15 @@ files:
215
241
  - spec/lib/reverse_asciidoctor/converters/br_spec.rb
216
242
  - spec/lib/reverse_asciidoctor/converters/code_spec.rb
217
243
  - spec/lib/reverse_asciidoctor/converters/div_spec.rb
244
+ - spec/lib/reverse_asciidoctor/converters/example_spec.rb
245
+ - spec/lib/reverse_asciidoctor/converters/express_ref_spec.rb
246
+ - spec/lib/reverse_asciidoctor/converters/ext_description_spec.rb
247
+ - spec/lib/reverse_asciidoctor/converters/ext_descriptions_spec.rb
218
248
  - spec/lib/reverse_asciidoctor/converters/figure_spec.rb
219
249
  - spec/lib/reverse_asciidoctor/converters/img_spec.rb
220
250
  - spec/lib/reverse_asciidoctor/converters/li_spec.rb
221
251
  - spec/lib/reverse_asciidoctor/converters/mark_spec.rb
252
+ - spec/lib/reverse_asciidoctor/converters/note_spec.rb
222
253
  - spec/lib/reverse_asciidoctor/converters/p_spec.rb
223
254
  - spec/lib/reverse_asciidoctor/converters/pre_spec.rb
224
255
  - spec/lib/reverse_asciidoctor/converters/q_spec.rb
@@ -228,6 +259,7 @@ files:
228
259
  - spec/lib/reverse_asciidoctor/converters_spec.rb
229
260
  - spec/lib/reverse_asciidoctor_spec.rb
230
261
  - spec/spec_helper.rb
262
+ - spec/support/shell_helpers.rb
231
263
  homepage: http://github.com/metanorma/reverse_adoc
232
264
  licenses:
233
265
  - BSD-2-Clause
@@ -247,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
279
  - !ruby/object:Gem::Version
248
280
  version: '0'
249
281
  requirements: []
250
- rubygems_version: 3.0.3
282
+ rubygems_version: 3.0.6
251
283
  signing_key:
252
284
  specification_version: 4
253
285
  summary: Generate AsciiDoc from HTML and Microsoft Word via CLI or library.
@@ -256,6 +288,8 @@ test_files:
256
288
  - spec/assets/basic.html
257
289
  - spec/assets/code.html
258
290
  - spec/assets/escapables.html
291
+ - spec/assets/external_images.docx
292
+ - spec/assets/external_images.html
259
293
  - spec/assets/from_the_wild.html
260
294
  - spec/assets/full_example.html
261
295
  - spec/assets/html_fragment.html
@@ -265,6 +299,8 @@ test_files:
265
299
  - spec/assets/quotation.html
266
300
  - spec/assets/tables.html
267
301
  - spec/assets/unknown_tags.html
302
+ - spec/bin/reverse_adoc_spec.rb
303
+ - spec/bin/w2a_spec.rb
268
304
  - spec/components/anchors_spec.rb
269
305
  - spec/components/basic_spec.rb
270
306
  - spec/components/code_spec.rb
@@ -284,10 +320,15 @@ test_files:
284
320
  - spec/lib/reverse_asciidoctor/converters/br_spec.rb
285
321
  - spec/lib/reverse_asciidoctor/converters/code_spec.rb
286
322
  - spec/lib/reverse_asciidoctor/converters/div_spec.rb
323
+ - spec/lib/reverse_asciidoctor/converters/example_spec.rb
324
+ - spec/lib/reverse_asciidoctor/converters/express_ref_spec.rb
325
+ - spec/lib/reverse_asciidoctor/converters/ext_description_spec.rb
326
+ - spec/lib/reverse_asciidoctor/converters/ext_descriptions_spec.rb
287
327
  - spec/lib/reverse_asciidoctor/converters/figure_spec.rb
288
328
  - spec/lib/reverse_asciidoctor/converters/img_spec.rb
289
329
  - spec/lib/reverse_asciidoctor/converters/li_spec.rb
290
330
  - spec/lib/reverse_asciidoctor/converters/mark_spec.rb
331
+ - spec/lib/reverse_asciidoctor/converters/note_spec.rb
291
332
  - spec/lib/reverse_asciidoctor/converters/p_spec.rb
292
333
  - spec/lib/reverse_asciidoctor/converters/pre_spec.rb
293
334
  - spec/lib/reverse_asciidoctor/converters/q_spec.rb
@@ -297,3 +338,4 @@ test_files:
297
338
  - spec/lib/reverse_asciidoctor/converters_spec.rb
298
339
  - spec/lib/reverse_asciidoctor_spec.rb
299
340
  - spec/spec_helper.rb
341
+ - spec/support/shell_helpers.rb