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
|
# File 'lib/docx2gfm.rb', line 11
def self.run
options = {}
options[:jekyll] = true
options[:ref_style_links] = true
parser = OptionParser.new do |opts|
opts.banner = 'Usage: docx2gfm [options]'
opts.on('-f', '--file FILE', '(required) The .docx file to convert to markdown') do |v|
options[:file] = v
end
opts.on('-j', '--[no-]jekyll', '(optional) Prefix the markdown output with a jekyll frontmatter. Default: --jekyll') do |v|
options[:jekyll] = v
end
opts.on('-r', '--[no-]ref-style-links', '(optional) Create reference style links at the end of the markdown. Default: --ref-style-links') do |v|
options[:ref_style_links] = v
end
opts.on('-h', '--help', 'Display this help screen') do
puts opts
exit
end
opts.on('-v', '--version', 'Show version of docx2gfm') do
puts Docx2gfm::VERSION
exit
end
end
begin
parser.parse!
mandatory = [:file]
missing = mandatory.select{ |param| options[param].nil? }
raise OptionParser::MissingArgument, missing.join(', ') unless missing.empty?
rescue OptionParser::ParseError => e
puts e
puts parser
exit
end
doc = DocxGfmConverter.new(options)
doc.process_markdown
puts doc
end
|