reverse_adoc 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/README.adoc +4 -294
  4. data/Rakefile +2 -13
  5. data/reverse_adoc.gemspec +2 -20
  6. metadata +5 -246
  7. data/.editorconfig +0 -15
  8. data/.github/workflows/rake.yml +0 -15
  9. data/.gitignore +0 -10
  10. data/.hound.yml +0 -5
  11. data/.rubocop.yml +0 -10
  12. data/LICENSE.txt +0 -25
  13. data/exe/reverse_adoc +0 -70
  14. data/exe/w2a +0 -72
  15. data/lib/reverse_adoc/cleaner.rb +0 -113
  16. data/lib/reverse_adoc/config.rb +0 -54
  17. data/lib/reverse_adoc/converters/a.rb +0 -42
  18. data/lib/reverse_adoc/converters/aside.rb +0 -16
  19. data/lib/reverse_adoc/converters/audio.rb +0 -29
  20. data/lib/reverse_adoc/converters/base.rb +0 -100
  21. data/lib/reverse_adoc/converters/blockquote.rb +0 -27
  22. data/lib/reverse_adoc/converters/br.rb +0 -15
  23. data/lib/reverse_adoc/converters/bypass.rb +0 -81
  24. data/lib/reverse_adoc/converters/code.rb +0 -56
  25. data/lib/reverse_adoc/converters/div.rb +0 -18
  26. data/lib/reverse_adoc/converters/drop.rb +0 -22
  27. data/lib/reverse_adoc/converters/em.rb +0 -55
  28. data/lib/reverse_adoc/converters/figure.rb +0 -25
  29. data/lib/reverse_adoc/converters/h.rb +0 -42
  30. data/lib/reverse_adoc/converters/head.rb +0 -23
  31. data/lib/reverse_adoc/converters/hr.rb +0 -15
  32. data/lib/reverse_adoc/converters/ignore.rb +0 -16
  33. data/lib/reverse_adoc/converters/img.rb +0 -93
  34. data/lib/reverse_adoc/converters/li.rb +0 -17
  35. data/lib/reverse_adoc/converters/mark.rb +0 -21
  36. data/lib/reverse_adoc/converters/math.rb +0 -31
  37. data/lib/reverse_adoc/converters/ol.rb +0 -64
  38. data/lib/reverse_adoc/converters/p.rb +0 -23
  39. data/lib/reverse_adoc/converters/pass_through.rb +0 -13
  40. data/lib/reverse_adoc/converters/pre.rb +0 -55
  41. data/lib/reverse_adoc/converters/q.rb +0 -16
  42. data/lib/reverse_adoc/converters/strong.rb +0 -52
  43. data/lib/reverse_adoc/converters/sub.rb +0 -16
  44. data/lib/reverse_adoc/converters/sup.rb +0 -16
  45. data/lib/reverse_adoc/converters/table.rb +0 -69
  46. data/lib/reverse_adoc/converters/td.rb +0 -83
  47. data/lib/reverse_adoc/converters/text.rb +0 -65
  48. data/lib/reverse_adoc/converters/th.rb +0 -14
  49. data/lib/reverse_adoc/converters/tr.rb +0 -22
  50. data/lib/reverse_adoc/converters/video.rb +0 -29
  51. data/lib/reverse_adoc/converters.rb +0 -32
  52. data/lib/reverse_adoc/errors.rb +0 -10
  53. data/lib/reverse_adoc/html_converter.rb +0 -61
  54. data/lib/reverse_adoc/version.rb +0 -3
  55. data/lib/reverse_adoc.rb +0 -27
  56. data/spec/assets/anchors.html +0 -30
  57. data/spec/assets/basic.html +0 -61
  58. data/spec/assets/code.html +0 -22
  59. data/spec/assets/escapables.html +0 -17
  60. data/spec/assets/external_images.docx +0 -0
  61. data/spec/assets/external_images.html +0 -35
  62. data/spec/assets/from_the_wild.html +0 -23
  63. data/spec/assets/full_example.html +0 -49
  64. data/spec/assets/html_fragment.html +0 -3
  65. data/spec/assets/lists.html +0 -137
  66. data/spec/assets/minimum.html +0 -4
  67. data/spec/assets/paragraphs.html +0 -24
  68. data/spec/assets/quotation.html +0 -12
  69. data/spec/assets/tables.html +0 -99
  70. data/spec/assets/unknown_tags.html +0 -9
  71. data/spec/bin/reverse_adoc_spec.rb +0 -33
  72. data/spec/bin/w2a_spec.rb +0 -35
  73. data/spec/components/anchors_spec.rb +0 -32
  74. data/spec/components/basic_spec.rb +0 -63
  75. data/spec/components/code_spec.rb +0 -25
  76. data/spec/components/escapables_spec.rb +0 -30
  77. data/spec/components/from_the_wild_spec.rb +0 -15
  78. data/spec/components/html_fragment_spec.rb +0 -9
  79. data/spec/components/lists_spec.rb +0 -90
  80. data/spec/components/paragraphs_spec.rb +0 -14
  81. data/spec/components/quotation_spec.rb +0 -12
  82. data/spec/components/tables_spec.rb +0 -42
  83. data/spec/components/unknown_tags_spec.rb +0 -41
  84. data/spec/lib/reverse_adoc/cleaner_spec.rb +0 -180
  85. data/spec/lib/reverse_adoc/config_spec.rb +0 -25
  86. data/spec/lib/reverse_adoc/converters/aside_spec.rb +0 -11
  87. data/spec/lib/reverse_adoc/converters/audio_spec.rb +0 -15
  88. data/spec/lib/reverse_adoc/converters/blockquote_spec.rb +0 -23
  89. data/spec/lib/reverse_adoc/converters/br_spec.rb +0 -9
  90. data/spec/lib/reverse_adoc/converters/code_spec.rb +0 -15
  91. data/spec/lib/reverse_adoc/converters/div_spec.rb +0 -15
  92. data/spec/lib/reverse_adoc/converters/figure_spec.rb +0 -10
  93. data/spec/lib/reverse_adoc/converters/img_spec.rb +0 -25
  94. data/spec/lib/reverse_adoc/converters/li_spec.rb +0 -11
  95. data/spec/lib/reverse_adoc/converters/mark_spec.rb +0 -10
  96. data/spec/lib/reverse_adoc/converters/p_spec.rb +0 -10
  97. data/spec/lib/reverse_adoc/converters/pre_spec.rb +0 -43
  98. data/spec/lib/reverse_adoc/converters/q_spec.rb +0 -10
  99. data/spec/lib/reverse_adoc/converters/strong_spec.rb +0 -21
  100. data/spec/lib/reverse_adoc/converters/text_spec.rb +0 -67
  101. data/spec/lib/reverse_adoc/converters/video_spec.rb +0 -15
  102. data/spec/lib/reverse_adoc/converters_spec.rb +0 -22
  103. data/spec/lib/reverse_adoc.rb +0 -90
  104. data/spec/spec_helper.rb +0 -25
  105. data/spec/support/shell_helpers.rb +0 -15
@@ -1,67 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc::Converters::Text do
4
- let(:converter) { ReverseAdoc::Converters::Text.new }
5
-
6
- it "treats newline within text as a single whitespace" do
7
- input = node_for("<p>foo\nbar</p>")
8
- result = converter.convert(input)
9
- expect(result).to eq "foo bar"
10
- end
11
-
12
- it "removes leading newlines" do
13
- input = node_for("<p>\n\nfoo bar</p>")
14
- result = converter.convert(input)
15
- expect(result).to eq "foo bar"
16
- end
17
-
18
- it "removes trailing newlines" do
19
- input = node_for("<p>foo bar\n\n</p>")
20
- result = converter.convert(input)
21
- expect(result).to eq "foo bar"
22
- end
23
-
24
- it "keeps nbsps" do
25
- input = node_for("<p>foo\u00A0bar \u00A0</p>")
26
- result = converter.convert(input)
27
- expect(result).to eq "foo&nbsp;bar &nbsp;"
28
- end
29
-
30
- it "keeps HTML characters" do
31
- input = node_for("<p>&lt;foo&gt;</p>")
32
- result = converter.convert(input)
33
- expect(result).to eq "<foo>"
34
- end
35
-
36
- it "escapes Link like characters in text" do
37
- input = node_for("<p>&lt;&lt;foo&gt;&gt;</p>")
38
- result = converter.convert(input)
39
- expect(result).to eq '\<<foo>>'
40
- end
41
-
42
- context "within backticks" do
43
- it "preserves single underscores" do
44
- input = node_for("<p>`foo_bar`</p>")
45
- result = converter.convert(input)
46
- expect(result).to eq "`foo_bar`"
47
- end
48
-
49
- it "preserves multiple underscores" do
50
- input = node_for("<p>`foo_bar __example__`</p>")
51
- result = converter.convert(input)
52
- expect(result).to eq "`foo_bar __example__`"
53
- end
54
-
55
- it "preserves single asterisks" do
56
- input = node_for("<p>`def foo *args`</p>")
57
- result = converter.convert(input)
58
- expect(result).to eq "`def foo *args`"
59
- end
60
-
61
- it "preserves multiple asterisks" do
62
- input = node_for("<p>`def foo 2***3`</p>")
63
- result = converter.convert(input)
64
- expect(result).to eq "`def foo 2***3`"
65
- end
66
- end
67
- end
@@ -1,15 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc::Converters::Video do
4
- let(:converter) { ReverseAdoc::Converters::Video.new }
5
-
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[]"
9
- end
10
-
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\"]"
14
- end
15
- end
@@ -1,22 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc::Converters do
4
- before { ReverseAdoc.config.unknown_tags = :raise }
5
- let(:converters) { ReverseAdoc::Converters }
6
-
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
12
-
13
- converters.register :foo, :foobar
14
- expect(converters.lookup(:foo)).to eq :foobar
15
-
16
- converters.unregister :foo
17
- expect do
18
- converters.lookup(:foo)
19
- end.to raise_error ReverseAdoc::UnknownTagError
20
- end
21
- end
22
- end
@@ -1,90 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc do
4
- let(:input) { File.read("spec/assets/minimum.html") }
5
- let(:document) { Nokogiri::HTML(input) }
6
-
7
- it "parses nokogiri documents" do
8
- expect { ReverseAdoc.convert(document) }.not_to raise_error
9
- end
10
-
11
- it "parses nokogiri elements" do
12
- expect { ReverseAdoc.convert(document.root) }.not_to raise_error
13
- end
14
-
15
- it "parses string input" do
16
- expect { ReverseAdoc.convert(input) }.not_to raise_error
17
- end
18
-
19
- it "behaves in a sane way when root element is nil" do
20
- expect(ReverseAdoc.convert(nil)).to eq ""
21
- end
22
-
23
- describe "#config" do
24
- it "stores a given configuration option" do
25
- ReverseAdoc.config.tag_border = true
26
- expect(ReverseAdoc.config.tag_border).to eq true
27
- end
28
-
29
- it "can be used as a block configurator as well" do
30
- ReverseAdoc.config do |config|
31
- expect(config.tag_border).to eq " "
32
- config.tag_border = true
33
- end
34
- expect(ReverseAdoc.config.tag_border).to eq true
35
- end
36
- end
37
-
38
- shared_examples "converting source with external images included" do |result|
39
- let(:temp_dir) do
40
- Pathname.new(ReverseAdoc.config.destination).dirname
41
- end
42
- let(:images_folder) { File.join(temp_dir, "images") }
43
-
44
- before do
45
- ReverseAdoc.config.destination = File.join(Dir.mktmpdir,
46
- "output.html")
47
- ReverseAdoc.config.sourcedir = Dir.mktmpdir
48
- ReverseAdoc.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
- ReverseAdoc.convert(
71
- ReverseAdoc.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
- ReverseAdoc.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) { 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"]
89
- end
90
- end
data/spec/spec_helper.rb DELETED
@@ -1,25 +0,0 @@
1
- require "simplecov"
2
-
3
- SimpleCov.profiles.define "gem" do
4
- add_filter "/spec/"
5
- add_filter "/autotest/"
6
- add_group "Libraries", "/lib/"
7
- end
8
- SimpleCov.start "gem"
9
-
10
- require "reverse_adoc"
11
- require "reverse_adoc/html_converter"
12
- require "word-to-markdown"
13
-
14
- Dir[File.join("spec", "support", "**", "*.rb")]
15
- .each { |f| require File.join(".", f) }
16
-
17
- RSpec.configure do |config|
18
- config.after(:each) do
19
- ReverseAdoc.instance_variable_set(:@config, nil)
20
- end
21
- end
22
-
23
- def node_for(html)
24
- Nokogiri::HTML.parse(html).root.child.child
25
- end
@@ -1,15 +0,0 @@
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