Class: WordToMarkdown

Inherits:
Object
  • Object
show all
Defined in:
lib/word-to-markdown.rb,
lib/word-to-markdown/version.rb,
lib/word-to-markdown/document.rb,
lib/word-to-markdown/converter.rb

Defined Under Namespace

Classes: Converter, Document

Constant Summary collapse

REVERSE_MARKDOWN_OPTIONS =
{
  unknown_tags: :bypass,
  github_flavored: true
}
VERSION =
"1.1.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, tmpdir = nil) ⇒ WordToMarkdown

Create a new WordToMarkdown object

input - a HTML string or path to an HTML file

Returns the WordToMarkdown object



28
29
30
31
32
# File 'lib/word-to-markdown.rb', line 28

def initialize(path, tmpdir = nil)
  @document = WordToMarkdown::Document.new path, tmpdir
  @converter = WordToMarkdown::Converter.new @document
  converter.convert!
end

Instance Attribute Details

#converterObject (readonly)

Returns the value of attribute converter.



16
17
18
# File 'lib/word-to-markdown.rb', line 16

def converter
  @converter
end

#documentObject (readonly)

Returns the value of attribute document.



16
17
18
# File 'lib/word-to-markdown.rb', line 16

def document
  @document
end

Class Method Details

.osObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/word-to-markdown.rb', line 35

def self.os
  @os ||= (
  host_os = RbConfig::CONFIG['host_os']
  case host_os
  when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
    :windows
  when /darwin|mac os/
    :macosx
  when /linux/
    :linux
  when /solaris|bsd/
    :unix
  else
    raise Error::WebDriverError, "unknown os: #{host_os.inspect}"
  end
  )
end

.run_command(*args) ⇒ Object



66
67
68
69
70
# File 'lib/word-to-markdown.rb', line 66

def self.run_command(*args)
  output, status = Open3.capture2e(soffice_path, *args)
  raise "Command `#{soffice_path} #{args.join(" ")}` failed: #{output}" if status != 0
  output
end

.soffice_pathObject



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/word-to-markdown.rb', line 53

def self.soffice_path
  case os
  when :macosx
    %w[~/Applications /Applications]
      .map  { |f| File.expand_path(File.join(f, "/LibreOffice.app/Contents/MacOS/soffice")) }
      .find { |f| File.file?(f) }
  when :windows
    'C:\Program Files (x86)\LibreOffice 4\program\soffice.exe'
  else
    "soffice"
  end
end

.soffice_versionObject



72
73
74
# File 'lib/word-to-markdown.rb', line 72

def self.soffice_version
  run_command('--version').strip.sub "LibreOffice ", ""
end

Instance Method Details

#inspectObject

Pretty print the class in console



77
78
79
# File 'lib/word-to-markdown.rb', line 77

def inspect
  "<WordToMarkdown path=\"#{@document.path}\">"
end

#to_sObject



81
82
83
# File 'lib/word-to-markdown.rb', line 81

def to_s
  document.to_s
end