word-to-markdown 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/word-to-markdown.rb +5 -3
- data/lib/word-to-markdown/converter.rb +1 -0
- data/lib/word-to-markdown/document.rb +5 -7
- data/lib/word-to-markdown/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d0a6d4dbb16a5c53ffc336d781b5ca275acaf61
|
4
|
+
data.tar.gz: 16c255b3f304c01a89d215500cdc9e235149e119
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b6ecd85ac312939fff436970472dc3d350b6d75d8a42bb82d3633a06f95ac8a970f04765da64f2ac5a2221ef492ed6ba7efd5b06a8e4ea850998826cc85a4b4
|
7
|
+
data.tar.gz: 4612cadf0ba9f7b3409a7d0d378f960084bcca8980e3b6ca1e7436dc67011a33dbbb7817641cb177b769f83e92abb09f29e8758b151e2d4076e3395d00ccd4f7
|
data/lib/word-to-markdown.rb
CHANGED
@@ -23,8 +23,8 @@ class WordToMarkdown
|
|
23
23
|
# input - a HTML string or path to an HTML file
|
24
24
|
#
|
25
25
|
# Returns the WordToMarkdown object
|
26
|
-
def initialize(path)
|
27
|
-
@document = WordToMarkdown::Document.new path
|
26
|
+
def initialize(path, tmpdir = nil)
|
27
|
+
@document = WordToMarkdown::Document.new path, tmpdir
|
28
28
|
@converter = WordToMarkdown::Converter.new @document
|
29
29
|
converter.convert!
|
30
30
|
end
|
@@ -44,7 +44,9 @@ class WordToMarkdown
|
|
44
44
|
|
45
45
|
def self.soffice_path
|
46
46
|
if RUBY_PLATFORM.include?("darwin")
|
47
|
-
|
47
|
+
%w[~/Applications /Applications]
|
48
|
+
.map { |f| File.join(f, "/LibreOffice.app/Contents/MacOS/soffice") }
|
49
|
+
.find { |f| File.file?(f) } || -> { raise RuntimeError.new("Coudln't find LibreOffice on your machine.") }.call
|
48
50
|
else
|
49
51
|
soffice_path ||= which("soffice")
|
50
52
|
soffice_path ||= which("soffice.bin")
|
@@ -1,11 +1,13 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
class WordToMarkdown
|
2
3
|
class Document
|
3
4
|
class NotFoundError < StandardError; end
|
4
5
|
|
5
|
-
attr_reader :path, :raw_html
|
6
|
+
attr_reader :path, :raw_html, :tmpdir
|
6
7
|
|
7
|
-
def initialize(path)
|
8
|
+
def initialize(path, tmpdir = nil)
|
8
9
|
@path = File.expand_path path, Dir.pwd
|
10
|
+
@tmpdir = tmpdir || Dir.mktmpdir
|
9
11
|
raise NotFoundError, "File #{@path} does not exist" unless File.exist?(@path)
|
10
12
|
end
|
11
13
|
|
@@ -76,10 +78,6 @@ class WordToMarkdown
|
|
76
78
|
string
|
77
79
|
end
|
78
80
|
|
79
|
-
def tmpdir
|
80
|
-
@tmpdir ||= Dir.mktmpdir
|
81
|
-
end
|
82
|
-
|
83
81
|
def dest_path
|
84
82
|
dest_filename = File.basename(path).gsub(/#{Regexp.escape(extension)}$/, ".html")
|
85
83
|
File.expand_path(dest_filename, tmpdir)
|
@@ -87,7 +85,7 @@ class WordToMarkdown
|
|
87
85
|
|
88
86
|
def raw_html
|
89
87
|
@raw_html ||= begin
|
90
|
-
WordToMarkdown::run_command '--headless', '--convert-to', 'html', path, '--outdir', tmpdir
|
88
|
+
WordToMarkdown::run_command '--headless', '--convert-to', 'html', "'#{path}'", '--outdir', tmpdir
|
91
89
|
html = File.read dest_path
|
92
90
|
File.delete dest_path
|
93
91
|
html
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: word-to-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Balter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reverse_markdown
|