reverse_adoc 0.2.3 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +8 -4
- data/.github/workflows/ubuntu.yml +10 -4
- data/.github/workflows/windows.yml +12 -5
- data/Gemfile +3 -1
- data/Gemfile.lock +84 -0
- data/README.adoc +36 -3
- data/bin/reverse_adoc +7 -0
- data/bin/w2a +5 -17
- data/lib/reverse_asciidoctor.rb +7 -47
- data/lib/reverse_asciidoctor/cleaner.rb +23 -0
- data/lib/reverse_asciidoctor/config.rb +2 -1
- data/lib/reverse_asciidoctor/converters/a.rb +6 -2
- data/lib/reverse_asciidoctor/converters/example.rb +17 -0
- data/lib/reverse_asciidoctor/converters/express_ref.rb +12 -0
- data/lib/reverse_asciidoctor/converters/ext_description.rb +16 -0
- data/lib/reverse_asciidoctor/converters/ext_descriptions.rb +12 -0
- data/lib/reverse_asciidoctor/converters/h.rb +17 -2
- data/lib/reverse_asciidoctor/converters/img.rb +23 -20
- data/lib/reverse_asciidoctor/converters/note.rb +17 -0
- data/lib/reverse_asciidoctor/html_converter.rb +56 -0
- data/lib/reverse_asciidoctor/smrl_description_converter.rb +45 -0
- data/lib/reverse_asciidoctor/version.rb +1 -1
- data/reverse_adoc.gemspec +1 -0
- data/spec/assets/anchors.html +8 -0
- data/spec/assets/external_images.docx +0 -0
- data/spec/assets/external_images.html +35 -0
- data/spec/bin/reverse_adoc_spec.rb +32 -0
- data/spec/bin/w2a_spec.rb +35 -0
- data/spec/components/anchors_spec.rb +5 -0
- data/spec/lib/reverse_asciidoctor/cleaner_spec.rb +24 -0
- data/spec/lib/reverse_asciidoctor/converters/example_spec.rb +22 -0
- data/spec/lib/reverse_asciidoctor/converters/express_ref_spec.rb +14 -0
- data/spec/lib/reverse_asciidoctor/converters/ext_description_spec.rb +20 -0
- data/spec/lib/reverse_asciidoctor/converters/ext_descriptions_spec.rb +13 -0
- data/spec/lib/reverse_asciidoctor/converters/note_spec.rb +22 -0
- data/spec/lib/reverse_asciidoctor_spec.rb +58 -5
- data/spec/spec_helper.rb +5 -0
- data/spec/support/shell_helpers.rb +15 -0
- metadata +45 -3
@@ -3,10 +3,11 @@ require 'tmpdir'
|
|
3
3
|
module ReverseAsciidoctor
|
4
4
|
class Config
|
5
5
|
attr_accessor :unknown_tags, :tag_border, :mathml2asciimath, :external_images,
|
6
|
-
:destination, :sourcedir, :image_counter, :image_counter_pattern
|
6
|
+
:destination, :sourcedir, :image_counter, :image_counter_pattern, :input_format
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@unknown_tags = :pass_through
|
10
|
+
@input_format = :html
|
10
11
|
@mathml2asciimath = false
|
11
12
|
@external_images = false
|
12
13
|
|
@@ -9,10 +9,14 @@ module ReverseAsciidoctor
|
|
9
9
|
title = extract_title(node)
|
10
10
|
id = node['id'] || node['name']
|
11
11
|
|
12
|
-
|
12
|
+
id = id&.gsub(/\s/, "")&.gsub(/__+/, "_")
|
13
|
+
|
14
|
+
if /^_Toc\d+$|^_GoBack$/.match id
|
15
|
+
""
|
16
|
+
elsif !id.nil? && !id.empty?
|
13
17
|
"[[#{id}]]"
|
14
18
|
elsif href.to_s.start_with?('#')
|
15
|
-
|
19
|
+
href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_")
|
16
20
|
if name.empty?
|
17
21
|
"<<#{href}>>"
|
18
22
|
else
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ReverseAsciidoctor
|
4
|
+
module Converters
|
5
|
+
class Example < Base
|
6
|
+
def convert(node, state = {})
|
7
|
+
<<~TEMPLATE
|
8
|
+
[example]
|
9
|
+
====
|
10
|
+
#{treat_children(node, state)}
|
11
|
+
====
|
12
|
+
TEMPLATE
|
13
|
+
end
|
14
|
+
end
|
15
|
+
register :example, Example.new
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ReverseAsciidoctor
|
4
|
+
module Converters
|
5
|
+
class ExtDescription < Base
|
6
|
+
def convert(node, state = {})
|
7
|
+
<<~TEMPLATE
|
8
|
+
(*"#{node['linkend']}"
|
9
|
+
#{treat_children(node, state)}
|
10
|
+
*)
|
11
|
+
TEMPLATE
|
12
|
+
end
|
13
|
+
end
|
14
|
+
register :ext_description, ExtDescription.new
|
15
|
+
end
|
16
|
+
end
|
@@ -3,9 +3,24 @@ module ReverseAsciidoctor
|
|
3
3
|
class H < Base
|
4
4
|
def convert(node, state = {})
|
5
5
|
id = node['id']
|
6
|
-
anchor = id ? "[[#{id}]]
|
6
|
+
anchor = id ? "[[#{id}]]" : ""
|
7
|
+
internal_anchor = treat_children_anchors(node, state) || ""
|
8
|
+
anchor.empty? and anchor = internal_anchor
|
9
|
+
anchor.empty? or anchor += "\n"
|
7
10
|
prefix = '=' * (node.name[/\d/].to_i + 1)
|
8
|
-
["\n", anchor, prefix, ' ',
|
11
|
+
["\n", anchor, prefix, ' ', treat_children_no_anchors(node, state), "\n"].join
|
12
|
+
end
|
13
|
+
|
14
|
+
def treat_children_no_anchors(node, state)
|
15
|
+
node.children.reject { |a| a.name == "a" }.inject('') do |memo, child|
|
16
|
+
memo << treat(child, state)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def treat_children_anchors(node, state)
|
21
|
+
node.children.select { |a| a.name == "a" }.inject('') do |memo, child|
|
22
|
+
memo << treat(child, state)
|
23
|
+
end
|
9
24
|
end
|
10
25
|
end
|
11
26
|
|
@@ -1,4 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require "fileutils"
|
2
|
+
require "pathname"
|
3
|
+
require "tempfile"
|
4
|
+
require "base64"
|
5
|
+
require "mimemagic"
|
2
6
|
|
3
7
|
module ReverseAsciidoctor
|
4
8
|
module Converters
|
@@ -22,25 +26,7 @@ module ReverseAsciidoctor
|
|
22
26
|
images_dir = dest_dir + 'images'
|
23
27
|
FileUtils.mkdir_p(images_dir)
|
24
28
|
|
25
|
-
ext =
|
26
|
-
|
27
|
-
if imgdata
|
28
|
-
file = Tempfile.new(["radoc", ".jpg"]) do |f|
|
29
|
-
f.binmode
|
30
|
-
f.write(Base64.strict_decode64(imgdata))
|
31
|
-
f.rewind
|
32
|
-
ext = MimeMagic.by_magic(f)
|
33
|
-
end
|
34
|
-
|
35
|
-
image_src_path = file.path
|
36
|
-
# puts "tempfile: #{file}"
|
37
|
-
|
38
|
-
else
|
39
|
-
ext = File.extname(src).strip.downcase[1..-1]
|
40
|
-
image_src_path = Pathname.new(ReverseAsciidoctor.config.sourcedir) + src
|
41
|
-
|
42
|
-
end
|
43
|
-
|
29
|
+
ext, image_src_path = determine_image_src_path(src, imgdata)
|
44
30
|
image_dest_path = images_dir + "#{image_number}.#{ext}"
|
45
31
|
|
46
32
|
# puts "image_dest_path: #{image_dest_path.to_s}"
|
@@ -52,6 +38,23 @@ module ReverseAsciidoctor
|
|
52
38
|
image_dest_path.relative_path_from(dest_dir)
|
53
39
|
end
|
54
40
|
|
41
|
+
def determine_image_src_path(src, imgdata)
|
42
|
+
return copy_temp_file(imgdata) if imgdata
|
43
|
+
|
44
|
+
ext = File.extname(src).strip.downcase[1..-1]
|
45
|
+
[ext, Pathname.new(ReverseAsciidoctor.config.sourcedir) + src]
|
46
|
+
end
|
47
|
+
|
48
|
+
def copy_temp_file(imgdata)
|
49
|
+
Tempfile.open(['radoc', '.jpg']) do |f|
|
50
|
+
f.binmode
|
51
|
+
f.write(Base64.strict_decode64(imgdata))
|
52
|
+
f.rewind
|
53
|
+
ext = MimeMagic.by_magic(f).subtype
|
54
|
+
[ext, f.path]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
55
58
|
def convert(node, state = {})
|
56
59
|
alt = node['alt']
|
57
60
|
src = node['src']
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ReverseAsciidoctor
|
4
|
+
module Converters
|
5
|
+
class Note < Base
|
6
|
+
def convert(node, state = {})
|
7
|
+
<<~TEMPLATE
|
8
|
+
[NOTE]
|
9
|
+
--
|
10
|
+
#{treat_children(node, state)}
|
11
|
+
--
|
12
|
+
TEMPLATE
|
13
|
+
end
|
14
|
+
end
|
15
|
+
register :note, Note.new
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'reverse_asciidoctor/converters/a'
|
4
|
+
require 'reverse_asciidoctor/converters/aside'
|
5
|
+
require 'reverse_asciidoctor/converters/audio'
|
6
|
+
require 'reverse_asciidoctor/converters/blockquote'
|
7
|
+
require 'reverse_asciidoctor/converters/br'
|
8
|
+
require 'reverse_asciidoctor/converters/bypass'
|
9
|
+
require 'reverse_asciidoctor/converters/code'
|
10
|
+
require 'reverse_asciidoctor/converters/div'
|
11
|
+
require 'reverse_asciidoctor/converters/drop'
|
12
|
+
require 'reverse_asciidoctor/converters/em'
|
13
|
+
require 'reverse_asciidoctor/converters/figure'
|
14
|
+
require 'reverse_asciidoctor/converters/h'
|
15
|
+
require 'reverse_asciidoctor/converters/head'
|
16
|
+
require 'reverse_asciidoctor/converters/hr'
|
17
|
+
require 'reverse_asciidoctor/converters/ignore'
|
18
|
+
require 'reverse_asciidoctor/converters/img'
|
19
|
+
require 'reverse_asciidoctor/converters/mark'
|
20
|
+
require 'reverse_asciidoctor/converters/li'
|
21
|
+
require 'reverse_asciidoctor/converters/ol'
|
22
|
+
require 'reverse_asciidoctor/converters/p'
|
23
|
+
require 'reverse_asciidoctor/converters/pass_through'
|
24
|
+
require 'reverse_asciidoctor/converters/pre'
|
25
|
+
require 'reverse_asciidoctor/converters/q'
|
26
|
+
require 'reverse_asciidoctor/converters/strong'
|
27
|
+
require 'reverse_asciidoctor/converters/sup'
|
28
|
+
require 'reverse_asciidoctor/converters/sub'
|
29
|
+
require 'reverse_asciidoctor/converters/table'
|
30
|
+
require 'reverse_asciidoctor/converters/td'
|
31
|
+
require 'reverse_asciidoctor/converters/th'
|
32
|
+
require 'reverse_asciidoctor/converters/text'
|
33
|
+
require 'reverse_asciidoctor/converters/tr'
|
34
|
+
require 'reverse_asciidoctor/converters/video'
|
35
|
+
require 'reverse_asciidoctor/converters/math'
|
36
|
+
|
37
|
+
module ReverseAsciidoctor
|
38
|
+
class HtmlConverter
|
39
|
+
def self.convert(input, options = {})
|
40
|
+
root = if input.is_a?(String)
|
41
|
+
then Nokogiri::HTML(input).root
|
42
|
+
elsif input.is_a?(Nokogiri::XML::Document)
|
43
|
+
then input.root
|
44
|
+
elsif input.is_a?(Nokogiri::XML::Node)
|
45
|
+
then input
|
46
|
+
end
|
47
|
+
|
48
|
+
root || (return '')
|
49
|
+
|
50
|
+
ReverseAsciidoctor.config.with(options) do
|
51
|
+
result = ReverseAsciidoctor::Converters.lookup(root.name).convert(root)
|
52
|
+
ReverseAsciidoctor.cleaner.tidy(result)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'reverse_asciidoctor/converters/a'
|
4
|
+
require 'reverse_asciidoctor/converters/blockquote'
|
5
|
+
require 'reverse_asciidoctor/converters/bypass'
|
6
|
+
require 'reverse_asciidoctor/converters/br'
|
7
|
+
require 'reverse_asciidoctor/converters/code'
|
8
|
+
require 'reverse_asciidoctor/converters/drop'
|
9
|
+
require 'reverse_asciidoctor/converters/em'
|
10
|
+
require 'reverse_asciidoctor/converters/example'
|
11
|
+
require 'reverse_asciidoctor/converters/ext_descriptions'
|
12
|
+
require 'reverse_asciidoctor/converters/ext_description'
|
13
|
+
require 'reverse_asciidoctor/converters/express_ref'
|
14
|
+
require 'reverse_asciidoctor/converters/head'
|
15
|
+
require 'reverse_asciidoctor/converters/hr'
|
16
|
+
require 'reverse_asciidoctor/converters/ignore'
|
17
|
+
require 'reverse_asciidoctor/converters/note'
|
18
|
+
require 'reverse_asciidoctor/converters/p'
|
19
|
+
require 'reverse_asciidoctor/converters/pass_through'
|
20
|
+
require 'reverse_asciidoctor/converters/q'
|
21
|
+
require 'reverse_asciidoctor/converters/strong'
|
22
|
+
require 'reverse_asciidoctor/converters/sup'
|
23
|
+
require 'reverse_asciidoctor/converters/sub'
|
24
|
+
require 'reverse_asciidoctor/converters/text'
|
25
|
+
|
26
|
+
module ReverseAsciidoctor
|
27
|
+
class SmrlDescriptionConverter
|
28
|
+
def self.convert(input, options = {})
|
29
|
+
root = if input.is_a?(String)
|
30
|
+
then Nokogiri::XML(input).root
|
31
|
+
elsif input.is_a?(Nokogiri::XML::Document)
|
32
|
+
then input.root
|
33
|
+
elsif input.is_a?(Nokogiri::XML::Node)
|
34
|
+
then input
|
35
|
+
end
|
36
|
+
|
37
|
+
root || (return '')
|
38
|
+
|
39
|
+
ReverseAsciidoctor.config.with(options) do
|
40
|
+
result = ReverseAsciidoctor::Converters.lookup(root.name).convert(root)
|
41
|
+
ReverseAsciidoctor.cleaner.tidy(result)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/reverse_adoc.gemspec
CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
# specify any dependencies here; for example:
|
23
23
|
s.add_dependency 'nokogiri', ">= 1.10.4"
|
24
24
|
s.add_dependency 'mathml2asciimath'
|
25
|
+
s.add_dependency 'mimemagic'
|
25
26
|
s.add_development_dependency 'rspec'
|
26
27
|
s.add_development_dependency 'simplecov'
|
27
28
|
s.add_development_dependency 'rake'
|
data/spec/assets/anchors.html
CHANGED
@@ -14,9 +14,17 @@
|
|
14
14
|
|
15
15
|
some text...
|
16
16
|
|
17
|
+
<a href="#a__b spaced">Double __ anchor with space</a>
|
18
|
+
|
19
|
+
Double __ anchor with space <a id="a__b spaced"/>
|
20
|
+
|
21
|
+
<a id="_Toc12345"/>
|
22
|
+
|
17
23
|
<img src="http://foobar.com/logo.png">
|
18
24
|
<img alt="foobar image" src="http://foobar.com/foobar.png">
|
19
25
|
<img alt="foobar image 2" title="this is the foobar image 2" src="http://foobar.com/foobar2.png">
|
20
26
|
some text...
|
27
|
+
|
28
|
+
<h1><a id="a__Foreword"></a>Text</h1>
|
21
29
|
</body>
|
22
30
|
</html>
|
Binary file
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd">
|
2
|
+
<?xml version="1.0" encoding="UTF-8"??><html xmlns="http://www.w3.org/1999/xhtml" style="margin: 0;">
|
3
|
+
<!--This file was converted to xhtml by LibreOffice - see http://cgit.freedesktop.org/libreoffice/core/tree/filter/source/xslt for the code.--><head profile="http://dublincore.org/documents/dcmi-terms/">
|
4
|
+
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8">
|
5
|
+
<meta name="DCTERMS.title" content="" xml:lang="en-US">
|
6
|
+
<meta name="DCTERMS.language" content="en-US" scheme="DCTERMS.RFC4646">
|
7
|
+
<meta name="DCTERMS.source" content="http://xml.openoffice.org/odf2xhtml">
|
8
|
+
<meta name="DCTERMS.creator" content="Nick Nicholas">
|
9
|
+
<meta name="DCTERMS.issued" content="2019-11-21T08:48:00" scheme="DCTERMS.W3CDTF">
|
10
|
+
<meta name="DCTERMS.contributor" content="Nick Nicholas">
|
11
|
+
<meta name="DCTERMS.modified" content="2019-11-21T10:01:00" scheme="DCTERMS.W3CDTF">
|
12
|
+
<meta name="DCTERMS.provenance" content="" xml:lang="en-US">
|
13
|
+
<meta name="DCTERMS.subject" content="," xml:lang="en-US">
|
14
|
+
<link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" hreflang="en">
|
15
|
+
<link rel="schema.DCTERMS" href="http://purl.org/dc/terms/" hreflang="en">
|
16
|
+
<link rel="schema.DCTYPE" href="http://purl.org/dc/dcmitype/" hreflang="en">
|
17
|
+
<link rel="schema.DCAM" href="http://purl.org/dc/dcam/" hreflang="en">
|
18
|
+
</head>
|
19
|
+
<body dir="ltr" style="max-width: 21.001cm; margin: 2.54cm 3.175cm;">
|
20
|
+
<h1 class="P3" style="clear: both; color: #2f5496; font-size: 16pt; font-family: Calibri Light; writing-mode: lr-tb; margin: 0.423cm 0 0cm;" align="left ! important">
|
21
|
+
<a id="a__Hello" style="margin: 0;"><span style="margin: 0;"></span></a><span class="T1" style="margin: 0;">Hello</span>
|
22
|
+
</h1>
|
23
|
+
<p class="P1" style="font-size: 12pt; font-family: Calibri; writing-mode: lr-tb; margin: 0;" align="left ! important"> </p>
|
24
|
+
<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="T3" style="vertical-align: super; font-size: 58%; margin: 0;">2</h1><span class="T1" style="margin: 0;">0</span></p>
|
25
|
+
<p class="P1" style="font-size: 12pt; font-family: Calibri; writing-mode: lr-tb; margin: 0;" align="left ! important"> </p>
|
26
|
+
<!--Next 'div' was a 'text:p'.--><div class="Standard" style="font-size: 12pt; font-family: Calibri; writing-mode: lr-tb; margin: 0;" align="left ! important">
|
27
|
+
<!--Next ' span' is a draw:frame. --><span style="margin: 0;"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block" style="margin: 0;"><mrow style="margin: 0;"><mrow style="margin: 0;"><mrow style="margin: 0;"></mrow><mrow style="margin: 0;"><mi style="margin: 0;">i</mi><mo stretchy="false" style="margin: 0;">=</mo><mn style="margin: 0;">1</mn></mrow></mrow><mrow style="margin: 0;"><mrow style="margin: 0;"></mrow><mi style="margin: 0;">n</mi><msubsup style="margin: 0;"><mi style="margin: 0;">β</mi><mn style="margin: 0;">2</mn><mi style="margin: 0;">i</mi></msubsup></mrow></mrow></math></span>
|
28
|
+
</div>
|
29
|
+
<div style="clear: both; line-height: 0; width: 0; height: 0; margin: 0; padding: 0;"> </div>
|
30
|
+
<!--Next 'div' was a 'text:p'.--><div class="Standard" style="font-size: 12pt; font-family: Calibri; writing-mode: lr-tb; margin: 0;" align="left ! important">
|
31
|
+
<a id="_GoBack" style="margin: 0;"></a><!--Next ' span' is a draw:frame. --><span style="height: 1.764cm; margin: 0cm; padding: 0; border: none; width: 1.764cm; font-size: 12pt; font-family: Calibri; text-align: center; vertical-align: top; background-color: transparent;" class="fr1" id="Εικόνα_2"><img style="height: 1.764cm; width: 1.764cm; margin: 0;" alt="" src="data:image/gif;base64,R0lGODlhZABkAIAAAAAAAP///ywAAAAAZABkAEAC+4yPqcvtD6OctNqLs968XwCGokd24kidYckuKri9cFvKQCzTdG7x+u+y+YDECqqIzByTzKbzCY1Kp9Sq9eoQKrTY1Ev57TJsuLA4Meylz8HTxMz2LOPFOR1ov+v3/L7/DxgoOEj4IcRVeLA2Bue3CEHGF2nYyDaJcWn5+LZ5lamm0tf5MHpWilYJ6INymmiQ52q0EqsBSythews5qwt60wscLDxMXGx8jJysvMzc7PwM7XmYWzh9SPuJmuq43Raq2ooQbpUdMT5Vbn4ela7+fdfu/h4Xv9stfS/vBr+uPa+Zz94/gPvADCRY0FdCfgdxBezSr1+Vh+Iaclu4KoSiKGsSL9YTRu1YSGMji5UkdnJYSpC8nq0M9hJYzF4zo9m8iTOnzigFAAAh/tNUaGlzIGZpbGUgd2FzIGNyZWF0ZWQgYnkNDUdyYXBoaWMgV29ya3Nob3CZIFByb2Zlc3Npb25hbCAyLjBhDQ1mcm9tIEFsY2hlbXkgTWluZHdvcmtzIEluYy4NaHR0cDovL3d3dy5taW5kd29ya3Nob3AuY29tDQ1UaGlzIGltYWdlIG1heSBoYXZlIGJlZW4gY3JlYXRlZCBieQ1hIHBhcnR5IG90aGVyIHRoYW4gQWxjaGVteSBNaW5kd29ya3MgSW5jLg0NVXNlIG5vIGhvb2tzADs="></span>
|
32
|
+
</div>
|
33
|
+
<div style="clear: both; line-height: 0; width: 0; height: 0; margin: 0; padding: 0;"> </div>
|
34
|
+
</body>
|
35
|
+
</html>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'bin/revrse_adoc' do
|
6
|
+
subject(:convert) do
|
7
|
+
ShellUtils.execute!("./bin/reverse_adoc -e -o test1 #{input_file_path}")
|
8
|
+
end
|
9
|
+
unless Gem.win_platform?
|
10
|
+
context 'when external images present' do
|
11
|
+
let(:input_file_path) { 'spec/assets/external_images.html' }
|
12
|
+
let(:images_folder) { 'images' }
|
13
|
+
|
14
|
+
after do
|
15
|
+
FileUtils.rm_rf(images_folder) if File.directory?(images_folder)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'Does not raise error' do
|
19
|
+
expect { convert }.to_not raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'exatracts images from source html' do
|
23
|
+
expect { convert }
|
24
|
+
.to(change do
|
25
|
+
Dir["#{images_folder}/*gif"]
|
26
|
+
.map { |entry| File.basename(entry) }
|
27
|
+
.sort
|
28
|
+
end.from([]).to(['001.gif']))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'bin/w2a' do
|
6
|
+
subject(:convert) do
|
7
|
+
ShellUtils.execute!("./bin/w2a -e -o test1 #{input_file_path}")
|
8
|
+
end
|
9
|
+
# TODO: fix github actions integration with libreoffice, currently it hangs
|
10
|
+
# when trying to use soffice binary
|
11
|
+
unless Gem.win_platform? ||
|
12
|
+
(Gem::Platform.local.os == 'darwin' && !ENV['GITHUB_ACTION'].nil?)
|
13
|
+
context 'when external images present' do
|
14
|
+
let(:input_file_path) { 'spec/assets/external_images.docx' }
|
15
|
+
let(:images_folder) { 'images' }
|
16
|
+
|
17
|
+
after do
|
18
|
+
FileUtils.rm_rf(images_folder) if File.directory?(images_folder)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'Does not raise error' do
|
22
|
+
expect { convert }.to_not raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'exatracts images from source html' do
|
26
|
+
expect { convert }
|
27
|
+
.to(change do
|
28
|
+
Dir["#{images_folder}/*gif"]
|
29
|
+
.map { |entry| File.basename(entry) }
|
30
|
+
.sort
|
31
|
+
end.from([]).to(['001.gif', '002.gif']))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|