-
Notifications
You must be signed in to change notification settings - Fork 4
/
w2a
executable file
·60 lines (48 loc) · 1.59 KB
/
w2a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env ruby
# frozen_string_literal: true
require "rubygems"
require "bundler/setup"
require "word-to-markdown"
require "optparse"
require "coradoc"
ARGV.push("-h") if ARGV.empty?
config = {
input_options: input_options = {},
input_processor: :docx,
output_options: output_options = {},
output_processor: :adoc,
}
destination = nil
OptionParser.new do |opts|
opts.banner = "Usage: w2a [options] <file>"
opts.on("-m", "--mathml2asciimath", "Convert MathML to AsciiMath") do |_v|
input_options[:mathml2asciimath] = true
end
opts.on("-oFILENAME", "--output=FILENAME", "Output file to write to") do |v|
destination = File.expand_path(v)
# puts "output goes to #{Coradoc::Input::HTML.config.destination}"
end
opts.on("-e", "--external-images", "Export images if data URI") do |_v|
input_options[:external_images] = true
end
opts.on("-v", "--version", "Version information") do |_v|
puts "Coradoc: v#{Coradoc::VERSION}"
puts "[dependency] WordToMarkdown: v#{WordToMarkdown::VERSION}"
if Gem.win_platform?
puts "[dependency] LibreOffice: version not available on Windows"
else
puts "[dependency] LibreOffice: v#{WordToMarkdown.soffice.version}"
end
exit
end
opts.on("-h", "--help", "Prints this help") do
puts opts
exit
end
end.parse!
filename = ARGV.pop
raise "Please provide an input file to process. Exiting." unless filename
if input_options[:external_images] && destination.nil?
raise "The -e | --external-images feature must be used with -o | --output. Exiting."
end
Coradoc::Converter.(filename, destination, **config)