reverse_adoc 1.0.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +16 -3
  3. data/.github/workflows/release.yml +19 -2
  4. data/Gemfile +5 -3
  5. data/README.adoc +21 -280
  6. data/Rakefile +4 -10
  7. data/lib/reverse_adoc/version.rb +3 -1
  8. data/lib/reverse_adoc.rb +16 -21
  9. data/reverse_adoc.gemspec +13 -21
  10. data/spec/reverse_adoc_spec.rb +28 -0
  11. data/spec/spec_helper.rb +5 -20
  12. metadata +21 -228
  13. data/.editorconfig +0 -15
  14. data/.gitignore +0 -10
  15. data/.hound.yml +0 -5
  16. data/.rubocop.yml +0 -10
  17. data/LICENSE.txt +0 -25
  18. data/exe/reverse_adoc +0 -70
  19. data/exe/w2a +0 -72
  20. data/lib/reverse_adoc/cleaner.rb +0 -113
  21. data/lib/reverse_adoc/config.rb +0 -54
  22. data/lib/reverse_adoc/converters/a.rb +0 -42
  23. data/lib/reverse_adoc/converters/aside.rb +0 -16
  24. data/lib/reverse_adoc/converters/audio.rb +0 -29
  25. data/lib/reverse_adoc/converters/base.rb +0 -100
  26. data/lib/reverse_adoc/converters/blockquote.rb +0 -27
  27. data/lib/reverse_adoc/converters/br.rb +0 -15
  28. data/lib/reverse_adoc/converters/bypass.rb +0 -81
  29. data/lib/reverse_adoc/converters/code.rb +0 -56
  30. data/lib/reverse_adoc/converters/div.rb +0 -18
  31. data/lib/reverse_adoc/converters/drop.rb +0 -22
  32. data/lib/reverse_adoc/converters/em.rb +0 -55
  33. data/lib/reverse_adoc/converters/figure.rb +0 -25
  34. data/lib/reverse_adoc/converters/h.rb +0 -42
  35. data/lib/reverse_adoc/converters/head.rb +0 -23
  36. data/lib/reverse_adoc/converters/hr.rb +0 -15
  37. data/lib/reverse_adoc/converters/ignore.rb +0 -16
  38. data/lib/reverse_adoc/converters/img.rb +0 -93
  39. data/lib/reverse_adoc/converters/li.rb +0 -17
  40. data/lib/reverse_adoc/converters/mark.rb +0 -21
  41. data/lib/reverse_adoc/converters/math.rb +0 -31
  42. data/lib/reverse_adoc/converters/ol.rb +0 -64
  43. data/lib/reverse_adoc/converters/p.rb +0 -23
  44. data/lib/reverse_adoc/converters/pass_through.rb +0 -13
  45. data/lib/reverse_adoc/converters/pre.rb +0 -55
  46. data/lib/reverse_adoc/converters/q.rb +0 -16
  47. data/lib/reverse_adoc/converters/strong.rb +0 -52
  48. data/lib/reverse_adoc/converters/sub.rb +0 -16
  49. data/lib/reverse_adoc/converters/sup.rb +0 -16
  50. data/lib/reverse_adoc/converters/table.rb +0 -69
  51. data/lib/reverse_adoc/converters/td.rb +0 -83
  52. data/lib/reverse_adoc/converters/text.rb +0 -65
  53. data/lib/reverse_adoc/converters/th.rb +0 -14
  54. data/lib/reverse_adoc/converters/tr.rb +0 -22
  55. data/lib/reverse_adoc/converters/video.rb +0 -29
  56. data/lib/reverse_adoc/converters.rb +0 -32
  57. data/lib/reverse_adoc/errors.rb +0 -10
  58. data/lib/reverse_adoc/html_converter.rb +0 -61
  59. data/spec/assets/anchors.html +0 -30
  60. data/spec/assets/basic.html +0 -61
  61. data/spec/assets/code.html +0 -22
  62. data/spec/assets/escapables.html +0 -17
  63. data/spec/assets/external_images.docx +0 -0
  64. data/spec/assets/external_images.html +0 -35
  65. data/spec/assets/from_the_wild.html +0 -23
  66. data/spec/assets/full_example.html +0 -49
  67. data/spec/assets/html_fragment.html +0 -3
  68. data/spec/assets/lists.html +0 -137
  69. data/spec/assets/minimum.html +0 -4
  70. data/spec/assets/paragraphs.html +0 -24
  71. data/spec/assets/quotation.html +0 -12
  72. data/spec/assets/tables.html +0 -99
  73. data/spec/assets/unknown_tags.html +0 -9
  74. data/spec/bin/reverse_adoc_spec.rb +0 -33
  75. data/spec/bin/w2a_spec.rb +0 -35
  76. data/spec/components/anchors_spec.rb +0 -32
  77. data/spec/components/basic_spec.rb +0 -63
  78. data/spec/components/code_spec.rb +0 -25
  79. data/spec/components/escapables_spec.rb +0 -30
  80. data/spec/components/from_the_wild_spec.rb +0 -15
  81. data/spec/components/html_fragment_spec.rb +0 -9
  82. data/spec/components/lists_spec.rb +0 -90
  83. data/spec/components/paragraphs_spec.rb +0 -14
  84. data/spec/components/quotation_spec.rb +0 -12
  85. data/spec/components/tables_spec.rb +0 -42
  86. data/spec/components/unknown_tags_spec.rb +0 -41
  87. data/spec/lib/reverse_adoc/cleaner_spec.rb +0 -180
  88. data/spec/lib/reverse_adoc/config_spec.rb +0 -25
  89. data/spec/lib/reverse_adoc/converters/aside_spec.rb +0 -11
  90. data/spec/lib/reverse_adoc/converters/audio_spec.rb +0 -15
  91. data/spec/lib/reverse_adoc/converters/blockquote_spec.rb +0 -23
  92. data/spec/lib/reverse_adoc/converters/br_spec.rb +0 -9
  93. data/spec/lib/reverse_adoc/converters/code_spec.rb +0 -15
  94. data/spec/lib/reverse_adoc/converters/div_spec.rb +0 -15
  95. data/spec/lib/reverse_adoc/converters/figure_spec.rb +0 -10
  96. data/spec/lib/reverse_adoc/converters/img_spec.rb +0 -25
  97. data/spec/lib/reverse_adoc/converters/li_spec.rb +0 -11
  98. data/spec/lib/reverse_adoc/converters/mark_spec.rb +0 -10
  99. data/spec/lib/reverse_adoc/converters/p_spec.rb +0 -10
  100. data/spec/lib/reverse_adoc/converters/pre_spec.rb +0 -43
  101. data/spec/lib/reverse_adoc/converters/q_spec.rb +0 -10
  102. data/spec/lib/reverse_adoc/converters/strong_spec.rb +0 -21
  103. data/spec/lib/reverse_adoc/converters/text_spec.rb +0 -67
  104. data/spec/lib/reverse_adoc/converters/video_spec.rb +0 -15
  105. data/spec/lib/reverse_adoc/converters_spec.rb +0 -22
  106. data/spec/lib/reverse_adoc.rb +0 -90
  107. data/spec/support/shell_helpers.rb +0 -15
@@ -1,9 +0,0 @@
1
- <html>
2
- <body>
3
- <p>
4
- <foo>
5
- <bar>Foo with bar</bar>
6
- </foo>
7
- </p>
8
- </body>
9
- </html>
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe "exe/reverse_adoc" do
6
- subject(:convert) do
7
- ShellUtils.execute!("./exe/reverse_adoc -e -o test1 #{input_file_path}")
8
- end
9
-
10
- unless Gem.win_platform?
11
- context "when external images present" do
12
- let(:input_file_path) { "spec/assets/external_images.html" }
13
- let(:images_folder) { "images" }
14
-
15
- after do
16
- FileUtils.rm_rf(images_folder) if File.directory?(images_folder)
17
- end
18
-
19
- it "Does not raise error" do
20
- expect { convert }.to_not raise_error
21
- end
22
-
23
- it "exatracts images from source html" do
24
- expect { convert }
25
- .to(change do
26
- Dir["#{images_folder}/*gif"]
27
- .map { |entry| File.basename(entry) }
28
- .sort
29
- end.from([]).to(["001.gif"]))
30
- end
31
- end
32
- end
33
- end
data/spec/bin/w2a_spec.rb DELETED
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe "exe/w2a" do
6
- subject(:convert) do
7
- ShellUtils.execute!("./exe/w2a -e -o test1 #{input_file_path}")
8
- end
9
-
10
- # TODO: fix github actions integration with libreoffice, currently it hangs
11
- # when trying to use soffice binary
12
- unless Gem.win_platform? ||
13
- (Gem::Platform.local.os == "darwin" && !ENV["GITHUB_ACTION"].nil?)
14
- context "when external images present" do
15
- let(:input_file_path) { "spec/assets/external_images.docx" }
16
- let(:images_folder) { "images" }
17
-
18
- after do
19
- FileUtils.rm_rf(images_folder) if File.directory?(images_folder)
20
- end
21
-
22
- it "Does not raise error" do
23
- expect { convert }.to_not raise_error
24
- end
25
-
26
- it "extracts images from source html" do
27
- expect { convert }
28
- .to(change do
29
- !Dir["#{images_folder}/*gif"]
30
- .map { |entry| File.basename(entry) }.empty?
31
- end.from(false).to(true))
32
- end
33
- end
34
- end
35
- end
@@ -1,32 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc do
4
- let(:input) { File.read("spec/assets/anchors.html") }
5
- let(:document) { Nokogiri::HTML(input) }
6
- subject { ReverseAdoc.convert(input) }
7
-
8
- it { is_expected.to include "http://foobar.com[Foobar]" }
9
- it { is_expected.to include "http://foobar.com[Fubar]" }
10
- it { is_expected.to include 'http://foobar.com[f\*\*\*\*\* up beyond all redemption]' }
11
- it { is_expected.to include "http://strong.foobar.com[*Strong foobar*]" }
12
-
13
- it {
14
- is_expected.to include "There should be space before but not after the anchor ( http://foobar.com[stripped])."
15
- }
16
-
17
- it {
18
- is_expected.to include " do not ignore link:foo.html[] anchor tags with no link text "
19
- }
20
- it {
21
- is_expected.to include " link <<content,internal jumplinks>> with anchors "
22
- }
23
- it {
24
- is_expected.to include " link <<content2>>internal jumplinks without anchors "
25
- }
26
- it { is_expected.to include " treat [[content]] as bookmarks " }
27
-
28
- it { is_expected.to include "<<a_bspaced,Double \\_\\_ anchor with space>>" }
29
- it { is_expected.to include "[[a_bspaced]]" }
30
- it { is_expected.to include "[[a_Foreword]]\n== Text" }
31
- it { is_expected.not_to include "[[_Toc12345]]" }
32
- end
@@ -1,63 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc do
4
- let(:input) { File.read("spec/assets/basic.html") }
5
- # let(:document) { Nokogiri::HTML(input) }
6
- subject { ReverseAdoc.convert(input) }
7
-
8
- it { is_expected.to match /plain text ?\n/ }
9
- it { is_expected.to match /\n== h1\n/ }
10
- it { is_expected.to match /\n\[\[A\]\]\n== h1 with anchor\n/ }
11
- it { is_expected.to match /\n=== h2\n/ }
12
- it { is_expected.to match /\n==== h3\n/ }
13
- it { is_expected.to match /\n===== h4\n/ }
14
- it { is_expected.to match /\n====== h5\n/ }
15
- it { is_expected.to match /\n======= h6\n/ }
16
-
17
- it { is_expected.to match /_em tag content_/ }
18
- it { is_expected.to match /before and after empty em tags/ }
19
- it { is_expected.to match /before and after em tags containing whitespace/ }
20
- it { is_expected.to match /_double em tags_/ }
21
- it { is_expected.to match /_double em tags in p tag_/ }
22
- it { is_expected.to match /a _em with leading and trailing_ whitespace/ }
23
- it {
24
- is_expected.to match /a _em with extra leading and trailing_ whitespace/
25
- }
26
-
27
- it { is_expected.to match /\*strong tag content\*/ }
28
- it { is_expected.to match /before and after empty strong tags/ }
29
- it {
30
- is_expected.to match /before and after strong tags containing whitespace/
31
- }
32
- it { is_expected.to match /\*double strong tags\*/ }
33
- it { is_expected.to match /\*double strong tags in p tag\*/ }
34
- it {
35
- is_expected.to match /before \*double strong tags containing whitespace\* after/
36
- }
37
- it {
38
- is_expected.to match /a \*strong with leading and trailing\* whitespace/
39
- }
40
- it {
41
- is_expected.to match /a \*strong with extra leading and trailing\* whitespace/
42
- }
43
-
44
- it { is_expected.to match /constrai\*\*ned\*\* strong/ }
45
- it { is_expected.to match /constrai__ned__ italic/ }
46
-
47
- it { is_expected.to match /_i tag content_/ }
48
- it { is_expected.to match /\*b tag content\*/ }
49
-
50
- it { is_expected.to match /H~2~O/ }
51
- it { is_expected.to match /A\^2\^B/ }
52
-
53
- it {
54
- is_expected.to match /br tags become double space followed by newline \+\n/
55
- }
56
- # it { should match /br tags XXX \n/ }
57
-
58
- it { is_expected.to match /before hr \n\* \* \*\n after hr/ }
59
-
60
- it { is_expected.to match /section 1\n ?\nsection 2/ }
61
-
62
- it { is_expected.to match /ignore abbr/ }
63
- end
@@ -1,25 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc do
4
- let(:input) { File.read("spec/assets/code.html") }
5
- let(:document) { Nokogiri::HTML(input) }
6
- subject { ReverseAdoc.convert(input) }
7
-
8
- it { is_expected.to match /inline `code` block/ }
9
- it { is_expected.to match /\nvar this;\nthis\.is/ }
10
- it { is_expected.to match /block"\)\nconsole/ }
11
-
12
- context "with github style code blocks" do
13
- subject { ReverseAdoc.convert(input) }
14
- it { is_expected.to match /inline `code` block/ }
15
- it { is_expected.to match /\n\.\.\.\.\nvar this;\nthis/ }
16
- it { is_expected.to match /it is"\) ?\n \n\.\.\.\./ }
17
- end
18
-
19
- context "code with indentation" do
20
- subject { ReverseAdoc.convert(input) }
21
- it { is_expected.to match(/^tell application "Foo"\n/) }
22
- it { is_expected.to match(/^ beep\n/) }
23
- it { is_expected.to match(/^end tell\n/) }
24
- end
25
- end
@@ -1,30 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc do
4
- let(:input) { File.read("spec/assets/escapables.html") }
5
- let(:document) { Nokogiri::HTML(input) }
6
- subject { ReverseAdoc.convert(input) }
7
-
8
- context "multiple asterisks" do
9
- it { is_expected.to include ' \*\*two asterisks\*\* ' }
10
- it { is_expected.to include ' \*\*\*three asterisks\*\*\* ' }
11
- it { is_expected.to include ' \*and*the\* ' }
12
- it { is_expected.to include " asterisc*word " }
13
- it { is_expected.to include ' asterisc**multword asterisks\*\*\* ' }
14
- end
15
-
16
- context "multiple underscores" do
17
- it { is_expected.to include ' \_\_two underscores\_\_ ' }
18
- it { is_expected.to include ' \_\_\_three underscores\_\_\_ ' }
19
- end
20
-
21
- context "multiple underscores with undersocre inside words and new lines" do
22
- it { is_expected.to include "another_undersocre" }
23
- it { is_expected.to include ' \_\_\_three__underscores\_\_\_ ' }
24
- end
25
-
26
- context "underscores within words in code blocks" do
27
- let(:expected_output) { "....\nvar theoretical_max_infin = 1.0;\n....\n" }
28
- it { is_expected.to include expected_output }
29
- end
30
- end
@@ -1,15 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc do
4
- let(:input) { File.read("spec/assets/from_the_wild.html") }
5
- let(:document) { Nokogiri::HTML(input) }
6
- subject { ReverseAdoc.convert(input) }
7
-
8
- it "should make sense of strong-crazy markup (as seen in the wild)" do
9
- expect(subject).to include "*. +\n \\*\\*\\* intentcast* : logo design *+*\n"
10
- end
11
-
12
- it "should not over escape * or _" do
13
- expect(subject).to include 'link:example.com/foo_bar[image::example.com/foo_bar.png[] I\_AM\_HELPFUL]'
14
- end
15
- end
@@ -1,9 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc do
4
- let(:input) { File.read("spec/assets/html_fragment.html") }
5
- let(:document) { Nokogiri::HTML(input) }
6
- subject { ReverseAdoc.convert(input) }
7
-
8
- it { is_expected.to eq("naked text 1\n\nparagraph text\n\nnaked text 2") }
9
- end
@@ -1,90 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc do
4
- let(:input) { File.read("spec/assets/lists.html") }
5
- let(:document) { Nokogiri::HTML(input) }
6
- subject { ReverseAdoc.convert(input) }
7
-
8
- it { is_expected.to match /\n\* unordered list entry\n/ }
9
- it { is_expected.to match /\n\* unordered list entry 2\n/ }
10
- it { is_expected.to match /\n. ordered list entry\n/ }
11
- it { is_expected.to match /\n. ordered list entry 2\n/ }
12
- it { is_expected.to match /\n. list entry 1st hierarchy\n/ }
13
- it { is_expected.to match /\n\*\* nested unsorted list entry\n/ }
14
- it { is_expected.to match /\n\.\.\. deep nested list entry\n/ }
15
-
16
- context "list anchors" do
17
- it { is_expected.to match /\n\[\[1\]\]\n\. arabic1\n/ }
18
- it { is_expected.to match /\n\[\[A\]\]\n\* upperalpha1\n/ }
19
- end
20
-
21
- context "list styles" do
22
- it { is_expected.to match /\n\[arabic\]\n\. arabic\n/ }
23
- it { is_expected.to match /\n\[loweralpha\]\n\. loweralpha\n/ }
24
- it { is_expected.to match /\n\[upperalpha\]\n\. upperalpha\n/ }
25
- it { is_expected.to match /\n\[lowerroman\]\n\. lowerroman\n/ }
26
- it { is_expected.to match /\n\[upperroman\]\n\. upperroman\n/ }
27
- it { is_expected.to match /\n\[type=disc\]\n\* disc\n/ }
28
- end
29
-
30
- context "list start, reversed" do
31
- it { is_expected.to match /\n\[start=3\]\n\. another ordered list entry\n/ }
32
- it {
33
- is_expected.to match /\n\[%reversed\]\n\. a reversed ordered list entry\n/
34
- }
35
- end
36
-
37
- context "nested list with no whitespace" do
38
- it { is_expected.to match /\n\* item a\n/ }
39
- it { is_expected.to match /\n\* item b\n/ }
40
- it { is_expected.to match /\n\*\* item bb\n/ }
41
- it { is_expected.to match /\n\*\* item bc\n/ }
42
- end
43
-
44
- context "nested list with lots of whitespace" do
45
- it { is_expected.to match /\n\* item wa \n/ }
46
- it { is_expected.to match /\n\* item wb \n/ }
47
- it { is_expected.to match /\n\*\* item wbb \n/ }
48
- it { is_expected.to match /\n\*\* item wbc \n/ }
49
- end
50
-
51
- context "lists containing links" do
52
- it { is_expected.to match /\n\* link:Basic_concepts\[1 Basic concepts\]\n/ }
53
- it {
54
- is_expected.to match /\n\* link:History_of_the_idea\[2 History of the idea\]\n/
55
- }
56
- it {
57
- is_expected.to match /\n\* link:Intelligence_explosion\[3 Intelligence explosion\]\n/
58
- }
59
- end
60
-
61
- context "lists containing embedded <p> tags" do
62
- xit { is_expected.to match /\n\* I want to have a party at my house!\n/ }
63
- end
64
-
65
- context "list item containing multiple <p> tags" do
66
- xit { is_expected.to match /\n\* li 1, p 1\n\n\* li 1, p 2\n/ }
67
- end
68
-
69
- context "it produces correct numbering" do
70
- it { is_expected.to include "\. one" }
71
- it { is_expected.to include "\.\. one one" }
72
- it { is_expected.to include "\.\. one two" }
73
- it { is_expected.to include "\. two" }
74
- it { is_expected.to include "\.\. two one" }
75
- it { is_expected.to include "\.\.\. two one one" }
76
- it { is_expected.to include "\.\.\. two one two" }
77
- it { is_expected.to include "\.\. two two" }
78
- it { is_expected.to include "\. three" }
79
- end
80
-
81
- context "properly embeds a nested list between adjacent list items" do
82
- it { is_expected.to match /\n\* alpha\n/ }
83
- it { is_expected.to match /\n\* bravo/ }
84
- it { is_expected.to match /\n\*\* bravo alpha\n/ }
85
- it { is_expected.to match /\n\*\* bravo bravo/ }
86
- it { is_expected.to match /\n\*\*\* bravo bravo alpha/ }
87
- it { is_expected.to match /\n\* charlie\n/ }
88
- it { is_expected.to match /\n\* delta\n/ }
89
- end
90
- end
@@ -1,14 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc do
4
- let(:input) { File.read("spec/assets/paragraphs.html") }
5
- let(:document) { Nokogiri::HTML(input) }
6
- subject { ReverseAdoc.convert(input) }
7
-
8
- it { is_expected.not_to start_with "\n\n" }
9
- it { is_expected.to start_with "First content\n\nSecond content\n\n" }
10
- it { is_expected.to include "\n\n_Complex_\n\n\.\.\.\.\n\n Content\n" }
11
- it { is_expected.to include "*Trailing whitespace:*" }
12
- it { is_expected.to include "*Trailing non-breaking space:&nbsp;*" }
13
- it { is_expected.to include "*_Combination:&nbsp;_*" }
14
- end
@@ -1,12 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc do
4
- let(:input) { File.read("spec/assets/quotation.html") }
5
- let(:document) { Nokogiri::HTML(input) }
6
- subject { ReverseAdoc.convert(input) }
7
-
8
- it { is_expected.to match /\n Block of code$/ }
9
- it {
10
- is_expected.to include "\n____\nFirst quoted paragraph\n\nSecond quoted paragraph\n____\n"
11
- }
12
- end
@@ -1,42 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc do
4
- let(:input) { File.read("spec/assets/tables.html") }
5
- let(:document) { Nokogiri::HTML(input) }
6
- subject { ReverseAdoc.convert(input) }
7
-
8
- it {
9
- is_expected.to match /\[\[A\]\]\n\|===\n\| \[\[C\]\]header 1 \| header 2 \| header 3\n\n/
10
- }
11
- it {
12
- is_expected.to match /\nh\| \[\[D\]\]data 1-1 \| data 2-1 \| data 3-1\n/
13
- }
14
- it { is_expected.to match /\nh\| data 1-2 \| data 2-2 \| data 3-2\n/ }
15
-
16
- it {
17
- is_expected.to match /\n\| _header oblique_ \| \*header bold\* \| `header code`\n\n/
18
- }
19
- it {
20
- is_expected.to match /\n\| _data oblique_ \| \*data bold\* \| `data code`\n/
21
- }
22
-
23
- it { is_expected.to match /\n\.2\+\| rowspan 2\n/ }
24
- it { is_expected.to match /\n2\+| colspan 2\n/ }
25
- it { is_expected.to match /\n2\.2\+| colrowspan 2\n/ }
26
-
27
- it { is_expected.to match /<\| horizontal left / }
28
- it { is_expected.to match /\^\| horizontal center / }
29
- it { is_expected.to match />\| horizontal right\n/ }
30
- it { is_expected.to match /\^\.\^\| center middle\n/ }
31
-
32
- it { is_expected.to match /\n\.Table _caption_\n\|===\n/ }
33
- # it { is_expected.to match /\n\[width=75%\]\n\|===\n\| 75% width table\n/ }
34
- it {
35
- is_expected.to match /\n\[frame=topbot,rules=cols\]\n\|===\n\| topbot\n/
36
- }
37
-
38
- it {
39
- is_expected.to match /\na|\nHello\n\nThis cell has multiple paragraphs\n\n/
40
- }
41
- it { is_expected.to match /\n\| This cell has a single paragraph\n/ }
42
- end
@@ -1,41 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc do
4
- let(:input) { File.read("spec/assets/unknown_tags.html") }
5
- let(:document) { Nokogiri::HTML(input) }
6
- let(:result) { ReverseAdoc.convert(input) }
7
-
8
- context "with unknown_tags = :pass_through" do
9
- before { ReverseAdoc.config.unknown_tags = :pass_through }
10
-
11
- it { expect(result).to include "<bar>Foo with bar</bar>" }
12
- end
13
-
14
- context "with unknown_tags = :raise" do
15
- before { ReverseAdoc.config.unknown_tags = :raise }
16
-
17
- it { expect { result }.to raise_error(ReverseAdoc::UnknownTagError) }
18
- end
19
-
20
- context "with unknown_tags = :drop" do
21
- before { ReverseAdoc.config.unknown_tags = :drop }
22
-
23
- it { expect(result).to eq "" }
24
- end
25
-
26
- context "with unknown_tags = :bypass" do
27
- before { ReverseAdoc.config.unknown_tags = :bypass }
28
-
29
- it { expect(result).to eq "Foo with bar\n\n" }
30
- end
31
-
32
- context "with unknown_tags = :something_wrong" do
33
- before { ReverseAdoc.config.unknown_tags = :something_wrong }
34
-
35
- it {
36
- expect do
37
- result
38
- end.to raise_error(ReverseAdoc::InvalidConfigurationError)
39
- }
40
- end
41
- end
@@ -1,180 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc::Cleaner do
4
- let(:cleaner) { ReverseAdoc::Cleaner.new }
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
-
30
- describe "#remove_newlines" do
31
- it "removes more than 2 subsequent newlines" do
32
- result = cleaner.remove_newlines("foo\n\n\nbar")
33
- expect(result).to eq "foo\n\nbar"
34
- end
35
-
36
- it "skips single and double newlines" do
37
- result = cleaner.remove_newlines("foo\nbar\n\nbaz")
38
- expect(result).to eq "foo\nbar\n\nbaz"
39
- end
40
- end
41
-
42
- describe "#remove_inner_whitespaces" do
43
- it "removes duplicate whitespaces from the string" do
44
- result = cleaner.remove_inner_whitespaces("foo bar")
45
- expect(result).to eq "foo bar"
46
- end
47
-
48
- it "performs changes for multiple lines" do
49
- result = cleaner.remove_inner_whitespaces("foo bar\nbar foo")
50
- expect(result).to eq "foo bar\nbar foo"
51
- end
52
-
53
- it "keeps leading whitespaces" do
54
- result = cleaner.remove_inner_whitespaces(" foo bar\n bar foo")
55
- expect(result).to eq " foo bar\n bar foo"
56
- end
57
-
58
- it "keeps trailing whitespaces" do
59
- result = cleaner.remove_inner_whitespaces("foo \n")
60
- expect(result).to eq "foo \n"
61
- end
62
-
63
- it "keeps trailing newlines" do
64
- result = cleaner.remove_inner_whitespaces("foo\n")
65
- expect(result).to eq "foo\n"
66
- end
67
-
68
- it "removes tabs as well" do
69
- result = cleaner.remove_inner_whitespaces("foo\t \tbar")
70
- expect(result).to eq "foo bar"
71
- end
72
-
73
- it "keeps lines that only contain whitespace" do
74
- result = cleaner.remove_inner_whitespaces("foo \nbar \n \n \nfoo")
75
- expect(result).to eq "foo \nbar \n \n \nfoo"
76
- end
77
- end
78
-
79
- describe "#clean_punctuation_characters" do
80
- it "removes whitespace between tag end and punctuation characters" do
81
- input = "**fat** . ~~strike~~ ? __italic__ ! "
82
- result = cleaner.clean_punctuation_characters(input)
83
- expect(result).to eq "**fat**. ~~strike~~? __italic__! "
84
- end
85
- end
86
-
87
- describe "#clean_tag_borders" do
88
- context "with default_border is set to space" do
89
- before { ReverseAdoc.config.tag_border = " " }
90
-
91
- # it 'removes not needed whitespaces from strong tags' do
92
- # input = "foo ** foobar ** bar"
93
- # result = cleaner.clean_tag_borders(input)
94
- # expect(result).to eq "foo **foobar** bar"
95
- # end
96
-
97
- # it 'remotes leading or trailing whitespaces independently' do
98
- # input = "1 **fat ** 2 ** fat** 3"
99
- # result = cleaner.clean_tag_borders(input)
100
- # expect(result).to eq "1 **fat** 2 **fat** 3"
101
- # end
102
-
103
- # it 'adds whitespaces if there are none' do
104
- # input = "1**fat**2"
105
- # result = cleaner.clean_tag_borders(input)
106
- # expect(result).to eq "1 **fat** 2"
107
- # end
108
-
109
- it "doesn't add whitespaces to underscore'ed elements if they are part of links" do
110
- input = "![im__age](sou__rce)"
111
- result = cleaner.clean_tag_borders(input)
112
- expect(result).to eq "![im__age](sou__rce)"
113
- end
114
-
115
- # it "still cleans up whitespaces that aren't inside a link" do
116
- # input = "now __italic __with following [under__scored](link)"
117
- # result = cleaner.clean_tag_borders(input)
118
- # expect(result).to eq "now __italic__ with following [under__scored](link)"
119
- # end
120
-
121
- # it 'cleans italic stuff as well' do
122
- # input = "1 __italic __ 2 __ italic__ 3__italic __4"
123
- # result = cleaner.clean_tag_borders(input)
124
- # expect(result).to eq "1 __italic__ 2 __italic__ 3 __italic__ 4"
125
- # end
126
-
127
- it "cleans strikethrough stuff as well" do
128
- input = "1 ~~italic ~~ 2 ~~ italic~~ 3~~italic ~~4"
129
- result = cleaner.clean_tag_borders(input)
130
- expect(result).to eq "1 ~~italic~~ 2 ~~italic~~ 3 ~~italic~~ 4"
131
- end
132
- end
133
-
134
- context "with default_border set to no space" do
135
- before { ReverseAdoc.config.tag_border = "" }
136
-
137
- # it 'removes not needed whitespaces from strong tags' do
138
- # input = "foo ** foobar ** bar"
139
- # result = cleaner.clean_tag_borders(input)
140
- # expect(result).to eq "foo **foobar** bar"
141
- # end
142
-
143
- # it 'remotes leading or trailing whitespaces independently' do
144
- # input = "1 **fat ** 2 ** fat** 3"
145
- # result = cleaner.clean_tag_borders(input)
146
- # expect(result).to eq "1 **fat** 2 **fat** 3"
147
- # end
148
-
149
- it "adds whitespaces if there are none" do
150
- input = "1**fat**2"
151
- result = cleaner.clean_tag_borders(input)
152
- expect(result).to eq "1**fat**2"
153
- end
154
-
155
- it "doesn't add whitespaces to underscore'ed elements if they are part of links" do
156
- input = "![im__age](sou__rce)"
157
- result = cleaner.clean_tag_borders(input)
158
- expect(result).to eq "![im__age](sou__rce)"
159
- end
160
-
161
- # it "still cleans up whitespaces that aren't inside a link" do
162
- # input = "now __italic __with following [under__scored](link)"
163
- # result = cleaner.clean_tag_borders(input)
164
- # expect(result).to eq "now __italic__with following [under__scored](link)"
165
- # end
166
-
167
- # it 'cleans italic stuff as well' do
168
- # input = "1 __italic __ 2 __ italic__ 3__italic __4"
169
- # result = cleaner.clean_tag_borders(input)
170
- # expect(result).to eq "1 __italic__ 2 __italic__ 3__italic__4"
171
- # end
172
-
173
- it "cleans strikethrough stuff as well" do
174
- input = "1 ~~italic ~~ 2 ~~ italic~~ 3~~italic ~~4"
175
- result = cleaner.clean_tag_borders(input)
176
- expect(result).to eq "1 ~~italic~~ 2 ~~italic~~ 3~~italic~~4"
177
- end
178
- end
179
- end
180
- end
@@ -1,25 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe ReverseAdoc::Config do
4
- describe "#with" do
5
- let(:config) { ReverseAdoc.config }
6
-
7
- it "takes additional options into account" do
8
- config.with(tag_border: :foobar) do
9
- expect(ReverseAdoc.config.tag_border).to eq :foobar
10
- end
11
- end
12
-
13
- it "returns the result of a given block" do
14
- expect(config.with { :something }).to eq :something
15
- end
16
-
17
- it "resets to original settings afterwards" do
18
- config.tag_border = :foo
19
- config.with(tag_border: :bar) do
20
- expect(ReverseAdoc.config.tag_border).to eq :bar
21
- end
22
- expect(ReverseAdoc.config.tag_border).to eq :foo
23
- end
24
- end
25
- end