reverse_adoc 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/README.adoc +4 -294
- data/Rakefile +2 -13
- data/reverse_adoc.gemspec +2 -20
- metadata +5 -246
- data/.editorconfig +0 -15
- data/.github/workflows/rake.yml +0 -15
- data/.gitignore +0 -10
- data/.hound.yml +0 -5
- data/.rubocop.yml +0 -10
- data/LICENSE.txt +0 -25
- data/exe/reverse_adoc +0 -70
- data/exe/w2a +0 -72
- data/lib/reverse_adoc/cleaner.rb +0 -113
- data/lib/reverse_adoc/config.rb +0 -54
- data/lib/reverse_adoc/converters/a.rb +0 -42
- data/lib/reverse_adoc/converters/aside.rb +0 -16
- data/lib/reverse_adoc/converters/audio.rb +0 -29
- data/lib/reverse_adoc/converters/base.rb +0 -100
- data/lib/reverse_adoc/converters/blockquote.rb +0 -27
- data/lib/reverse_adoc/converters/br.rb +0 -15
- data/lib/reverse_adoc/converters/bypass.rb +0 -81
- data/lib/reverse_adoc/converters/code.rb +0 -56
- data/lib/reverse_adoc/converters/div.rb +0 -18
- data/lib/reverse_adoc/converters/drop.rb +0 -22
- data/lib/reverse_adoc/converters/em.rb +0 -55
- data/lib/reverse_adoc/converters/figure.rb +0 -25
- data/lib/reverse_adoc/converters/h.rb +0 -42
- data/lib/reverse_adoc/converters/head.rb +0 -23
- data/lib/reverse_adoc/converters/hr.rb +0 -15
- data/lib/reverse_adoc/converters/ignore.rb +0 -16
- data/lib/reverse_adoc/converters/img.rb +0 -93
- data/lib/reverse_adoc/converters/li.rb +0 -17
- data/lib/reverse_adoc/converters/mark.rb +0 -21
- data/lib/reverse_adoc/converters/math.rb +0 -31
- data/lib/reverse_adoc/converters/ol.rb +0 -64
- data/lib/reverse_adoc/converters/p.rb +0 -23
- data/lib/reverse_adoc/converters/pass_through.rb +0 -13
- data/lib/reverse_adoc/converters/pre.rb +0 -55
- data/lib/reverse_adoc/converters/q.rb +0 -16
- data/lib/reverse_adoc/converters/strong.rb +0 -52
- data/lib/reverse_adoc/converters/sub.rb +0 -16
- data/lib/reverse_adoc/converters/sup.rb +0 -16
- data/lib/reverse_adoc/converters/table.rb +0 -69
- data/lib/reverse_adoc/converters/td.rb +0 -83
- data/lib/reverse_adoc/converters/text.rb +0 -65
- data/lib/reverse_adoc/converters/th.rb +0 -14
- data/lib/reverse_adoc/converters/tr.rb +0 -22
- data/lib/reverse_adoc/converters/video.rb +0 -29
- data/lib/reverse_adoc/converters.rb +0 -32
- data/lib/reverse_adoc/errors.rb +0 -10
- data/lib/reverse_adoc/html_converter.rb +0 -61
- data/lib/reverse_adoc/version.rb +0 -3
- data/lib/reverse_adoc.rb +0 -27
- data/spec/assets/anchors.html +0 -30
- data/spec/assets/basic.html +0 -61
- data/spec/assets/code.html +0 -22
- data/spec/assets/escapables.html +0 -17
- data/spec/assets/external_images.docx +0 -0
- data/spec/assets/external_images.html +0 -35
- data/spec/assets/from_the_wild.html +0 -23
- data/spec/assets/full_example.html +0 -49
- data/spec/assets/html_fragment.html +0 -3
- data/spec/assets/lists.html +0 -137
- data/spec/assets/minimum.html +0 -4
- data/spec/assets/paragraphs.html +0 -24
- data/spec/assets/quotation.html +0 -12
- data/spec/assets/tables.html +0 -99
- data/spec/assets/unknown_tags.html +0 -9
- data/spec/bin/reverse_adoc_spec.rb +0 -33
- data/spec/bin/w2a_spec.rb +0 -35
- data/spec/components/anchors_spec.rb +0 -32
- data/spec/components/basic_spec.rb +0 -63
- data/spec/components/code_spec.rb +0 -25
- data/spec/components/escapables_spec.rb +0 -30
- data/spec/components/from_the_wild_spec.rb +0 -15
- data/spec/components/html_fragment_spec.rb +0 -9
- data/spec/components/lists_spec.rb +0 -90
- data/spec/components/paragraphs_spec.rb +0 -14
- data/spec/components/quotation_spec.rb +0 -12
- data/spec/components/tables_spec.rb +0 -42
- data/spec/components/unknown_tags_spec.rb +0 -41
- data/spec/lib/reverse_adoc/cleaner_spec.rb +0 -180
- data/spec/lib/reverse_adoc/config_spec.rb +0 -25
- data/spec/lib/reverse_adoc/converters/aside_spec.rb +0 -11
- data/spec/lib/reverse_adoc/converters/audio_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters/blockquote_spec.rb +0 -23
- data/spec/lib/reverse_adoc/converters/br_spec.rb +0 -9
- data/spec/lib/reverse_adoc/converters/code_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters/div_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters/figure_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/img_spec.rb +0 -25
- data/spec/lib/reverse_adoc/converters/li_spec.rb +0 -11
- data/spec/lib/reverse_adoc/converters/mark_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/p_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/pre_spec.rb +0 -43
- data/spec/lib/reverse_adoc/converters/q_spec.rb +0 -10
- data/spec/lib/reverse_adoc/converters/strong_spec.rb +0 -21
- data/spec/lib/reverse_adoc/converters/text_spec.rb +0 -67
- data/spec/lib/reverse_adoc/converters/video_spec.rb +0 -15
- data/spec/lib/reverse_adoc/converters_spec.rb +0 -22
- data/spec/lib/reverse_adoc.rb +0 -90
- data/spec/spec_helper.rb +0 -25
- 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 bar "
|
28
|
-
end
|
29
|
-
|
30
|
-
it "keeps HTML characters" do
|
31
|
-
input = node_for("<p><foo></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><<foo>></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
|
data/spec/lib/reverse_adoc.rb
DELETED
@@ -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
|