diff --git a/lib/word-to-markdown.rb b/lib/word-to-markdown.rb index c81d506..8551eb6 100644 --- a/lib/word-to-markdown.rb +++ b/lib/word-to-markdown.rb @@ -63,14 +63,21 @@ def self.soffice_path end end + def self.soffice? + @soffice ||= !(soffice_path.nil? || soffice_version.nil?) + end + def self.run_command(*args) + raise "LibreOffice executable not found" unless soffice? output, status = Open3.capture2e(soffice_path, *args) raise "Command `#{soffice_path} #{args.join(" ")}` failed: #{output}" if status != 0 output end def self.soffice_version - run_command('--version').strip.sub "LibreOffice ", "" + return if soffice_path.nil? + output, status = Open3.capture2e(soffice_path, "--version") + output.strip.sub "LibreOffice ", "" if status == 0 end # Pretty print the class in console diff --git a/test/test_word_to_markdown.rb b/test/test_word_to_markdown.rb index 395a2f2..04c1a11 100644 --- a/test/test_word_to_markdown.rb +++ b/test/test_word_to_markdown.rb @@ -53,4 +53,8 @@ class TestWordToMarkdown < Test::Unit::TestCase should "handle files with spaces" do validate_fixture "file with space", "This is paragraph text." end + + should "know the soffice version" do + assert_match /\d\.\d\.\d\.\d .*/, WordToMarkdown.soffice_version + end end diff --git a/test/test_word_to_markdown_lists.rb b/test/test_word_to_markdown_lists.rb index 60f4cbb..f42b750 100644 --- a/test/test_word_to_markdown_lists.rb +++ b/test/test_word_to_markdown_lists.rb @@ -11,11 +11,11 @@ class TestWordToMarkdownLists < Test::Unit::TestCase end should "parse nested ols" do - validate_fixture "nested-ol", "1. One\n 1. Sub one\n 2. Sub two\n\n2. Two\n 1. Sub one\n 1. Sub sub one\n 2. Sub sub two\n\n 2. Sub two\n\n3. Three" + validate_fixture "nested-ol", "1. One\n 1. Sub one\n 2. Sub two\n2. Two\n 1. Sub one\n 1. Sub sub one\n 2. Sub sub two\n 2. Sub two\n3. Three" end should "parse nested uls" do - validate_fixture "nested-ul", "- One\n - Sub one\n - Sub sub one\n - Sub sub two\n\n - Sub two\n\n- Two" + validate_fixture "nested-ul", "- One\n - Sub one\n - Sub sub one\n - Sub sub two\n - Sub two\n- Two" end should "parse lists with links" do