reverse_adoc 0.3.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/release.yml +4 -3
  3. data/Gemfile +1 -1
  4. data/Rakefile +7 -7
  5. data/exe/reverse_adoc +11 -11
  6. data/exe/w2a +15 -16
  7. data/lib/reverse_adoc/cleaner.rb +17 -18
  8. data/lib/reverse_adoc/config.rb +7 -7
  9. data/lib/reverse_adoc/converters/a.rb +24 -24
  10. data/lib/reverse_adoc/converters/aside.rb +6 -4
  11. data/lib/reverse_adoc/converters/audio.rb +16 -21
  12. data/lib/reverse_adoc/converters/base.rb +79 -5
  13. data/lib/reverse_adoc/converters/blockquote.rb +16 -7
  14. data/lib/reverse_adoc/converters/br.rb +5 -1
  15. data/lib/reverse_adoc/converters/bypass.rb +38 -34
  16. data/lib/reverse_adoc/converters/code.rb +42 -1
  17. data/lib/reverse_adoc/converters/div.rb +7 -3
  18. data/lib/reverse_adoc/converters/drop.rb +6 -2
  19. data/lib/reverse_adoc/converters/em.rb +44 -7
  20. data/lib/reverse_adoc/converters/figure.rb +10 -6
  21. data/lib/reverse_adoc/converters/h.rb +19 -11
  22. data/lib/reverse_adoc/converters/head.rb +7 -2
  23. data/lib/reverse_adoc/converters/hr.rb +5 -1
  24. data/lib/reverse_adoc/converters/ignore.rb +6 -2
  25. data/lib/reverse_adoc/converters/img.rb +29 -19
  26. data/lib/reverse_adoc/converters/li.rb +6 -13
  27. data/lib/reverse_adoc/converters/mark.rb +11 -2
  28. data/lib/reverse_adoc/converters/math.rb +13 -2
  29. data/lib/reverse_adoc/converters/ol.rb +44 -26
  30. data/lib/reverse_adoc/converters/p.rb +13 -7
  31. data/lib/reverse_adoc/converters/pass_through.rb +5 -1
  32. data/lib/reverse_adoc/converters/pre.rb +23 -10
  33. data/lib/reverse_adoc/converters/q.rb +6 -2
  34. data/lib/reverse_adoc/converters/strong.rb +41 -6
  35. data/lib/reverse_adoc/converters/sub.rb +6 -2
  36. data/lib/reverse_adoc/converters/sup.rb +6 -2
  37. data/lib/reverse_adoc/converters/table.rb +28 -23
  38. data/lib/reverse_adoc/converters/td.rb +32 -16
  39. data/lib/reverse_adoc/converters/text.rb +16 -14
  40. data/lib/reverse_adoc/converters/th.rb +4 -6
  41. data/lib/reverse_adoc/converters/tr.rb +7 -7
  42. data/lib/reverse_adoc/converters/video.rb +16 -23
  43. data/lib/reverse_adoc/converters.rb +2 -3
  44. data/lib/reverse_adoc/html_converter.rb +48 -43
  45. data/lib/reverse_adoc/version.rb +1 -1
  46. data/lib/reverse_adoc.rb +9 -9
  47. data/reverse_adoc.gemspec +4 -1
  48. data/spec/assets/basic.html +3 -0
  49. data/spec/bin/reverse_adoc_spec.rb +9 -8
  50. data/spec/bin/w2a_spec.rb +12 -12
  51. data/spec/components/anchors_spec.rb +18 -12
  52. data/spec/components/basic_spec.rb +28 -14
  53. data/spec/components/code_spec.rb +2 -4
  54. data/spec/components/escapables_spec.rb +4 -6
  55. data/spec/components/from_the_wild_spec.rb +2 -4
  56. data/spec/components/html_fragment_spec.rb +2 -3
  57. data/spec/components/lists_spec.rb +12 -8
  58. data/spec/components/paragraphs_spec.rb +2 -3
  59. data/spec/components/quotation_spec.rb +5 -5
  60. data/spec/components/tables_spec.rb +22 -11
  61. data/spec/components/unknown_tags_spec.rb +13 -10
  62. data/spec/lib/reverse_adoc/cleaner_spec.rb +70 -71
  63. data/spec/lib/reverse_adoc/config_spec.rb +5 -6
  64. data/spec/lib/reverse_adoc/converters/aside_spec.rb +2 -3
  65. data/spec/lib/reverse_adoc/converters/audio_spec.rb +3 -5
  66. data/spec/lib/reverse_adoc/converters/blockquote_spec.rb +5 -6
  67. data/spec/lib/reverse_adoc/converters/br_spec.rb +2 -2
  68. data/spec/lib/reverse_adoc/converters/code_spec.rb +3 -5
  69. data/spec/lib/reverse_adoc/converters/div_spec.rb +3 -5
  70. data/spec/lib/reverse_adoc/converters/figure_spec.rb +2 -4
  71. data/spec/lib/reverse_adoc/converters/img_spec.rb +5 -7
  72. data/spec/lib/reverse_adoc/converters/li_spec.rb +2 -4
  73. data/spec/lib/reverse_adoc/converters/mark_spec.rb +4 -4
  74. data/spec/lib/reverse_adoc/converters/p_spec.rb +2 -3
  75. data/spec/lib/reverse_adoc/converters/pre_spec.rb +8 -9
  76. data/spec/lib/reverse_adoc/converters/q_spec.rb +3 -3
  77. data/spec/lib/reverse_adoc/converters/strong_spec.rb +9 -8
  78. data/spec/lib/reverse_adoc/converters/text_spec.rb +13 -14
  79. data/spec/lib/reverse_adoc/converters/video_spec.rb +7 -9
  80. data/spec/lib/reverse_adoc/converters_spec.rb +9 -6
  81. data/spec/lib/reverse_adoc.rb +25 -25
  82. data/spec/spec_helper.rb +11 -11
  83. data/spec/support/shell_helpers.rb +1 -1
  84. metadata +17 -3
@@ -1,28 +1,27 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ReverseAdoc::Converters::Text do
4
-
5
4
  let(:converter) { ReverseAdoc::Converters::Text.new }
6
5
 
7
- it 'treats newline within text as a single whitespace' do
6
+ it "treats newline within text as a single whitespace" do
8
7
  input = node_for("<p>foo\nbar</p>")
9
8
  result = converter.convert(input)
10
- expect(result).to eq 'foo bar'
9
+ expect(result).to eq "foo bar"
11
10
  end
12
11
 
13
- it 'removes leading newlines' do
12
+ it "removes leading newlines" do
14
13
  input = node_for("<p>\n\nfoo bar</p>")
15
14
  result = converter.convert(input)
16
- expect(result).to eq 'foo bar'
15
+ expect(result).to eq "foo bar"
17
16
  end
18
17
 
19
- it 'removes trailing newlines' do
18
+ it "removes trailing newlines" do
20
19
  input = node_for("<p>foo bar\n\n</p>")
21
20
  result = converter.convert(input)
22
- expect(result).to eq 'foo bar'
21
+ expect(result).to eq "foo bar"
23
22
  end
24
23
 
25
- it 'keeps nbsps' do
24
+ it "keeps nbsps" do
26
25
  input = node_for("<p>foo\u00A0bar \u00A0</p>")
27
26
  result = converter.convert(input)
28
27
  expect(result).to eq "foo&nbsp;bar &nbsp;"
@@ -40,29 +39,29 @@ describe ReverseAdoc::Converters::Text do
40
39
  expect(result).to eq '\<<foo>>'
41
40
  end
42
41
 
43
- context 'within backticks' do
42
+ context "within backticks" do
44
43
  it "preserves single underscores" do
45
44
  input = node_for("<p>`foo_bar`</p>")
46
45
  result = converter.convert(input)
47
- expect(result).to eq '`foo_bar`'
46
+ expect(result).to eq "`foo_bar`"
48
47
  end
49
48
 
50
49
  it "preserves multiple underscores" do
51
50
  input = node_for("<p>`foo_bar __example__`</p>")
52
51
  result = converter.convert(input)
53
- expect(result).to eq '`foo_bar __example__`'
52
+ expect(result).to eq "`foo_bar __example__`"
54
53
  end
55
54
 
56
55
  it "preserves single asterisks" do
57
56
  input = node_for("<p>`def foo *args`</p>")
58
57
  result = converter.convert(input)
59
- expect(result).to eq '`def foo *args`'
58
+ expect(result).to eq "`def foo *args`"
60
59
  end
61
60
 
62
61
  it "preserves multiple asterisks" do
63
62
  input = node_for("<p>`def foo 2***3`</p>")
64
63
  result = converter.convert(input)
65
- expect(result).to eq '`def foo 2***3`'
64
+ expect(result).to eq "`def foo 2***3`"
66
65
  end
67
66
  end
68
67
  end
@@ -1,17 +1,15 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ReverseAdoc::Converters::Video do
4
-
5
4
  let(:converter) { ReverseAdoc::Converters::Video.new }
6
5
 
7
- it 'converts audio with no attributes' do
8
- node = node_for("<audio src='example.mp3'/>")
9
- expect(converter.convert(node)).to include "video::example.mp3[]"
6
+ it "converts video with no attributes" do
7
+ node = node_for("<video src='example.mp4'/>")
8
+ expect(converter.convert(node)).to include "video::example.mp4[]"
10
9
  end
11
10
 
12
- it 'converts audio with full set of attributes' do
13
- node = node_for("<audio id='A' src='example.mp3' loop='loop'/>")
14
- expect(converter.convert(node)).to include "[[A]]\nvideo::example.mp3[options=\"loop\"]"
11
+ it "converts video with full set of attributes" do
12
+ node = node_for("<video id='A' src='example.mp4' loop='loop'/>")
13
+ expect(converter.convert(node)).to include "[[A]]\nvideo::example.mp4[options=\"loop\"]"
15
14
  end
16
-
17
15
  end
@@ -1,19 +1,22 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ReverseAdoc::Converters do
4
4
  before { ReverseAdoc.config.unknown_tags = :raise }
5
5
  let(:converters) { ReverseAdoc::Converters }
6
6
 
7
- describe '.register and .unregister' do
8
- it 'adds a converter mapping to the list' do
9
- expect { converters.lookup(:foo) }.to raise_error ReverseAdoc::UnknownTagError
7
+ describe ".register and .unregister" do
8
+ it "adds a converter mapping to the list" do
9
+ expect do
10
+ converters.lookup(:foo)
11
+ end.to raise_error ReverseAdoc::UnknownTagError
10
12
 
11
13
  converters.register :foo, :foobar
12
14
  expect(converters.lookup(:foo)).to eq :foobar
13
15
 
14
16
  converters.unregister :foo
15
- expect { converters.lookup(:foo) }.to raise_error ReverseAdoc::UnknownTagError
17
+ expect do
18
+ converters.lookup(:foo)
19
+ end.to raise_error ReverseAdoc::UnknownTagError
16
20
  end
17
21
  end
18
-
19
22
  end
@@ -1,49 +1,49 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe ReverseAdoc do
4
- let(:input) { File.read('spec/assets/minimum.html') }
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 { ReverseAdoc.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 { ReverseAdoc.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 { ReverseAdoc.convert(input) }.not_to raise_error
17
17
  end
18
18
 
19
- it 'behaves in a sane way when root element is nil' do
20
- expect(ReverseAdoc.convert(nil)).to eq ''
19
+ it "behaves in a sane way when root element is nil" do
20
+ expect(ReverseAdoc.convert(nil)).to eq ""
21
21
  end
22
22
 
23
- describe '#config' do
24
- it 'stores a given configuration option' do
23
+ describe "#config" do
24
+ it "stores a given configuration option" do
25
25
  ReverseAdoc.config.tag_border = true
26
26
  expect(ReverseAdoc.config.tag_border).to eq true
27
27
  end
28
28
 
29
- it 'can be used as a block configurator as well' do
29
+ it "can be used as a block configurator as well" do
30
30
  ReverseAdoc.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(ReverseAdoc.config.tag_border).to eq true
35
35
  end
36
36
  end
37
37
 
38
- shared_examples 'converting source with external images included' do |result|
38
+ shared_examples "converting source with external images included" do |result|
39
39
  let(:temp_dir) do
40
40
  Pathname.new(ReverseAdoc.config.destination).dirname
41
41
  end
42
- let(:images_folder) { File.join(temp_dir, 'images') }
42
+ let(:images_folder) { File.join(temp_dir, "images") }
43
43
 
44
44
  before do
45
45
  ReverseAdoc.config.destination = File.join(Dir.mktmpdir,
46
- 'output.html')
46
+ "output.html")
47
47
  ReverseAdoc.config.sourcedir = Dir.mktmpdir
48
48
  ReverseAdoc.config.external_images = true
49
49
  end
@@ -52,7 +52,7 @@ describe ReverseAdoc do
52
52
  FileUtils.rm_rf(temp_dir)
53
53
  end
54
54
 
55
- it 'Creates local files from external URI' do
55
+ it "Creates local files from external URI" do
56
56
  expect { convert }
57
57
  .to(change do
58
58
  Dir["#{images_folder}/*gif"]
@@ -64,27 +64,27 @@ describe ReverseAdoc do
64
64
 
65
65
  # TODO: fix github actions integration with libreoffice, currently it hangs
66
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
67
+ unless Gem::Platform.local.os == "darwin" && !ENV["GITHUB_ACTION"].nil?
68
+ context "when docx file input" do
69
69
  subject(:convert) do
70
70
  ReverseAdoc.convert(
71
71
  ReverseAdoc.cleaner.preprocess_word_html(input.document.html),
72
- WordToMarkdown::REVERSE_MARKDOWN_OPTIONS
72
+ WordToMarkdown::REVERSE_MARKDOWN_OPTIONS,
73
73
  )
74
74
  end
75
75
  let(:input) do
76
- WordToMarkdown.new('spec/assets/external_images.docx',
76
+ WordToMarkdown.new("spec/assets/external_images.docx",
77
77
  ReverseAdoc.config.sourcedir)
78
78
  end
79
- it_behaves_like 'converting source with external images included',
80
- ['001.gif', '002.gif']
79
+ it_behaves_like "converting source with external images included",
80
+ ["001.gif", "002.gif"]
81
81
  end
82
82
  end
83
83
 
84
- context 'when html file input' do
84
+ context "when html file input" do
85
85
  subject(:convert) { ReverseAdoc.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']
86
+ let(:input) { File.read("spec/assets/external_images.html") }
87
+ it_behaves_like "converting source with external images included",
88
+ ["001.gif"]
89
89
  end
90
90
  end
data/spec/spec_helper.rb CHANGED
@@ -1,18 +1,18 @@
1
- require 'simplecov'
1
+ require "simplecov"
2
2
 
3
- SimpleCov.profiles.define 'gem' do
4
- add_filter '/spec/'
5
- add_filter '/autotest/'
6
- add_group 'Libraries', '/lib/'
3
+ SimpleCov.profiles.define "gem" do
4
+ add_filter "/spec/"
5
+ add_filter "/autotest/"
6
+ add_group "Libraries", "/lib/"
7
7
  end
8
- SimpleCov.start 'gem'
8
+ SimpleCov.start "gem"
9
9
 
10
- require 'reverse_adoc'
11
- require 'reverse_adoc/html_converter'
12
- require 'word-to-markdown'
10
+ require "reverse_adoc"
11
+ require "reverse_adoc/html_converter"
12
+ require "word-to-markdown"
13
13
 
14
- Dir[File.join('spec', 'support', '**', '*.rb')]
15
- .each { |f| require File.join('.', f) }
14
+ Dir[File.join("spec", "support", "**", "*.rb")]
15
+ .each { |f| require File.join(".", f) }
16
16
 
17
17
  RSpec.configure do |config|
18
18
  config.after(:each) do
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'open3'
3
+ require "open3"
4
4
 
5
5
  module ShellUtils
6
6
  class ShellExcutionError < StandardError; end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reverse_adoc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-07-24 00:00:00.000000000 Z
11
+ date: 2024-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: coradoc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: marcel
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -282,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
296
  - !ruby/object:Gem::Version
283
297
  version: '0'
284
298
  requirements: []
285
- rubygems_version: 3.3.26
299
+ rubygems_version: 3.3.27
286
300
  signing_key:
287
301
  specification_version: 4
288
302
  summary: Generate AsciiDoc from HTML and Microsoft Word via CLI or library.