reverse_adoc 0.3.6 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +4 -3
- data/Gemfile +1 -1
- data/Rakefile +7 -7
- data/exe/reverse_adoc +11 -11
- data/exe/w2a +15 -16
- data/lib/reverse_adoc/cleaner.rb +17 -18
- data/lib/reverse_adoc/config.rb +7 -7
- data/lib/reverse_adoc/converters/a.rb +24 -24
- data/lib/reverse_adoc/converters/aside.rb +6 -4
- data/lib/reverse_adoc/converters/audio.rb +16 -21
- data/lib/reverse_adoc/converters/base.rb +79 -5
- data/lib/reverse_adoc/converters/blockquote.rb +16 -7
- data/lib/reverse_adoc/converters/br.rb +5 -1
- data/lib/reverse_adoc/converters/bypass.rb +38 -34
- data/lib/reverse_adoc/converters/code.rb +42 -1
- data/lib/reverse_adoc/converters/div.rb +7 -3
- data/lib/reverse_adoc/converters/drop.rb +6 -2
- data/lib/reverse_adoc/converters/em.rb +44 -7
- data/lib/reverse_adoc/converters/figure.rb +10 -6
- data/lib/reverse_adoc/converters/h.rb +19 -11
- data/lib/reverse_adoc/converters/head.rb +7 -2
- data/lib/reverse_adoc/converters/hr.rb +5 -1
- data/lib/reverse_adoc/converters/ignore.rb +6 -2
- data/lib/reverse_adoc/converters/img.rb +29 -19
- data/lib/reverse_adoc/converters/li.rb +6 -13
- data/lib/reverse_adoc/converters/mark.rb +11 -2
- data/lib/reverse_adoc/converters/math.rb +13 -2
- data/lib/reverse_adoc/converters/ol.rb +44 -26
- data/lib/reverse_adoc/converters/p.rb +13 -7
- data/lib/reverse_adoc/converters/pass_through.rb +5 -1
- data/lib/reverse_adoc/converters/pre.rb +23 -10
- data/lib/reverse_adoc/converters/q.rb +6 -2
- data/lib/reverse_adoc/converters/strong.rb +41 -6
- data/lib/reverse_adoc/converters/sub.rb +6 -2
- data/lib/reverse_adoc/converters/sup.rb +6 -2
- data/lib/reverse_adoc/converters/table.rb +28 -23
- data/lib/reverse_adoc/converters/td.rb +32 -16
- data/lib/reverse_adoc/converters/text.rb +19 -19
- data/lib/reverse_adoc/converters/th.rb +4 -6
- data/lib/reverse_adoc/converters/tr.rb +7 -7
- data/lib/reverse_adoc/converters/video.rb +16 -23
- data/lib/reverse_adoc/converters.rb +2 -3
- data/lib/reverse_adoc/html_converter.rb +48 -43
- data/lib/reverse_adoc/version.rb +1 -1
- data/lib/reverse_adoc.rb +9 -9
- data/reverse_adoc.gemspec +6 -3
- data/spec/assets/basic.html +3 -0
- data/spec/bin/reverse_adoc_spec.rb +9 -8
- data/spec/bin/w2a_spec.rb +12 -12
- data/spec/components/anchors_spec.rb +18 -12
- data/spec/components/basic_spec.rb +28 -14
- data/spec/components/code_spec.rb +2 -4
- data/spec/components/escapables_spec.rb +4 -6
- data/spec/components/from_the_wild_spec.rb +2 -4
- data/spec/components/html_fragment_spec.rb +2 -3
- data/spec/components/lists_spec.rb +12 -8
- data/spec/components/paragraphs_spec.rb +2 -3
- data/spec/components/quotation_spec.rb +5 -5
- data/spec/components/tables_spec.rb +22 -11
- data/spec/components/unknown_tags_spec.rb +13 -10
- data/spec/lib/reverse_adoc/cleaner_spec.rb +70 -71
- data/spec/lib/reverse_adoc/config_spec.rb +5 -6
- data/spec/lib/reverse_adoc/converters/aside_spec.rb +2 -3
- data/spec/lib/reverse_adoc/converters/audio_spec.rb +3 -5
- data/spec/lib/reverse_adoc/converters/blockquote_spec.rb +5 -6
- data/spec/lib/reverse_adoc/converters/br_spec.rb +2 -2
- data/spec/lib/reverse_adoc/converters/code_spec.rb +3 -5
- data/spec/lib/reverse_adoc/converters/div_spec.rb +3 -5
- data/spec/lib/reverse_adoc/converters/figure_spec.rb +2 -4
- data/spec/lib/reverse_adoc/converters/img_spec.rb +5 -7
- data/spec/lib/reverse_adoc/converters/li_spec.rb +2 -4
- data/spec/lib/reverse_adoc/converters/mark_spec.rb +4 -4
- data/spec/lib/reverse_adoc/converters/p_spec.rb +2 -3
- data/spec/lib/reverse_adoc/converters/pre_spec.rb +8 -9
- data/spec/lib/reverse_adoc/converters/q_spec.rb +3 -3
- data/spec/lib/reverse_adoc/converters/strong_spec.rb +9 -8
- data/spec/lib/reverse_adoc/converters/text_spec.rb +21 -16
- data/spec/lib/reverse_adoc/converters/video_spec.rb +7 -9
- data/spec/lib/reverse_adoc/converters_spec.rb +9 -6
- data/spec/lib/reverse_adoc.rb +25 -25
- data/spec/spec_helper.rb +11 -11
- data/spec/support/shell_helpers.rb +1 -1
- metadata +20 -6
@@ -1,62 +1,67 @@
|
|
1
|
-
require
|
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
|
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
|
9
|
+
expect(result).to eq "foo bar"
|
11
10
|
end
|
12
11
|
|
13
|
-
it
|
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
|
15
|
+
expect(result).to eq "foo bar"
|
17
16
|
end
|
18
17
|
|
19
|
-
it
|
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
|
21
|
+
expect(result).to eq "foo bar"
|
23
22
|
end
|
24
23
|
|
25
|
-
it
|
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 bar "
|
29
28
|
end
|
30
29
|
|
31
|
-
it
|
30
|
+
it "keeps HTML characters" do
|
32
31
|
input = node_for("<p><foo></p>")
|
33
32
|
result = converter.convert(input)
|
34
|
-
expect(result).to eq
|
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>>'
|
35
40
|
end
|
36
41
|
|
37
|
-
context
|
42
|
+
context "within backticks" do
|
38
43
|
it "preserves single underscores" do
|
39
44
|
input = node_for("<p>`foo_bar`</p>")
|
40
45
|
result = converter.convert(input)
|
41
|
-
expect(result).to eq
|
46
|
+
expect(result).to eq "`foo_bar`"
|
42
47
|
end
|
43
48
|
|
44
49
|
it "preserves multiple underscores" do
|
45
50
|
input = node_for("<p>`foo_bar __example__`</p>")
|
46
51
|
result = converter.convert(input)
|
47
|
-
expect(result).to eq
|
52
|
+
expect(result).to eq "`foo_bar __example__`"
|
48
53
|
end
|
49
54
|
|
50
55
|
it "preserves single asterisks" do
|
51
56
|
input = node_for("<p>`def foo *args`</p>")
|
52
57
|
result = converter.convert(input)
|
53
|
-
expect(result).to eq
|
58
|
+
expect(result).to eq "`def foo *args`"
|
54
59
|
end
|
55
60
|
|
56
61
|
it "preserves multiple asterisks" do
|
57
62
|
input = node_for("<p>`def foo 2***3`</p>")
|
58
63
|
result = converter.convert(input)
|
59
|
-
expect(result).to eq
|
64
|
+
expect(result).to eq "`def foo 2***3`"
|
60
65
|
end
|
61
66
|
end
|
62
67
|
end
|
@@ -1,17 +1,15 @@
|
|
1
|
-
require
|
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
|
8
|
-
node = node_for("<
|
9
|
-
expect(converter.convert(node)).to include "video::example.
|
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
|
13
|
-
node = node_for("<
|
14
|
-
expect(converter.convert(node)).to include "[[A]]\nvideo::example.
|
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
|
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
|
8
|
-
it
|
9
|
-
expect
|
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
|
17
|
+
expect do
|
18
|
+
converters.lookup(:foo)
|
19
|
+
end.to raise_error ReverseAdoc::UnknownTagError
|
16
20
|
end
|
17
21
|
end
|
18
|
-
|
19
22
|
end
|
data/spec/lib/reverse_adoc.rb
CHANGED
@@ -1,49 +1,49 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
2
|
|
3
3
|
describe ReverseAdoc do
|
4
|
-
let(:input) { File.read(
|
4
|
+
let(:input) { File.read("spec/assets/minimum.html") }
|
5
5
|
let(:document) { Nokogiri::HTML(input) }
|
6
6
|
|
7
|
-
it
|
7
|
+
it "parses nokogiri documents" do
|
8
8
|
expect { ReverseAdoc.convert(document) }.not_to raise_error
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
11
|
+
it "parses nokogiri elements" do
|
12
12
|
expect { ReverseAdoc.convert(document.root) }.not_to raise_error
|
13
13
|
end
|
14
14
|
|
15
|
-
it
|
15
|
+
it "parses string input" do
|
16
16
|
expect { ReverseAdoc.convert(input) }.not_to raise_error
|
17
17
|
end
|
18
18
|
|
19
|
-
it
|
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
|
24
|
-
it
|
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
|
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
|
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,
|
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
|
-
|
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
|
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 ==
|
68
|
-
context
|
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(
|
76
|
+
WordToMarkdown.new("spec/assets/external_images.docx",
|
77
77
|
ReverseAdoc.config.sourcedir)
|
78
78
|
end
|
79
|
-
it_behaves_like
|
80
|
-
[
|
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
|
84
|
+
context "when html file input" do
|
85
85
|
subject(:convert) { ReverseAdoc.convert(input) }
|
86
|
-
let(:input) { File.read(
|
87
|
-
it_behaves_like
|
88
|
-
[
|
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
|
1
|
+
require "simplecov"
|
2
2
|
|
3
|
-
SimpleCov.profiles.define
|
4
|
-
add_filter
|
5
|
-
add_filter
|
6
|
-
add_group
|
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
|
8
|
+
SimpleCov.start "gem"
|
9
9
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
10
|
+
require "reverse_adoc"
|
11
|
+
require "reverse_adoc/html_converter"
|
12
|
+
require "word-to-markdown"
|
13
13
|
|
14
|
-
Dir[File.join(
|
15
|
-
.each { |f| require File.join(
|
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
|
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.
|
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:
|
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
|
@@ -44,14 +58,14 @@ dependencies:
|
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
61
|
+
version: '1.13'
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
68
|
+
version: '1.13'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: codeclimate-test-reporter
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -275,14 +289,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
275
289
|
requirements:
|
276
290
|
- - ">="
|
277
291
|
- !ruby/object:Gem::Version
|
278
|
-
version: 2.
|
292
|
+
version: 2.7.0
|
279
293
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
280
294
|
requirements:
|
281
295
|
- - ">="
|
282
296
|
- !ruby/object:Gem::Version
|
283
297
|
version: '0'
|
284
298
|
requirements: []
|
285
|
-
rubygems_version: 3.
|
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.
|