bin/maruku in maruku-0.4.2.1 vs bin/maruku in maruku-0.5.0
- old
+ new
@@ -2,23 +2,46 @@
require 'maruku'
require 'optparse'
export = :html
+break_on_error = false
+using_math = false
+using_mathml = false
+output_file = nil
-OptionParser.new do |opts|
+opt = OptionParser.new do |opts|
opts.banner = "Usage: maruku [options] [file1.md [file2.md ..."
opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
MaRuKu::Globals[:verbose] = v end
opts.on("-u", "--[no-]unsafe", "Use unsafe features") do |v|
MaRuKu::Globals[:unsafe_features] = v end
-
+ opts.on("-b", "Break on error") do |v|
+ break_on_error = true end
- opts.on_tail("--pdf", "Write PDF" ) do export = :pdf end
+
+ opts.on("-i", "--math-images ENGINE", "Uses ENGINE to render TeX to PNG.") do |s|
+ using_math = true
+ MaRuKu::Globals[:html_png_engine] = s
+ $stderr.puts "Using png engine #{s}."
+ end
+
+ opts.on("-m", "--math-engine ENGINE", "Uses ENGINE to render MathML") do |s|
+ using_math = true
+ using_mathml = true
+ MaRuKu::Globals[:html_math_engine] = s
+ end
+
+ opts.on("-o", "--output FILE", "Output filename") do |s|
+ output_file = s
+ end
+
+ opts.on_tail("--pdf", "Write PDF","First writes LaTeX, then calls pdflatex." ) do export = :pdf end
opts.on_tail("--html", "Write HTML") do export = :html end
+ opts.on_tail("--html-frag", "Write the contents of the BODY.") do export = :html_frag end
opts.on_tail("--tex", "Write LaTeX" ) do export = :tex end
opts.on_tail("--inspect", "Shows the parsing result" ) do export = :inspect end
opts.on_tail("--version", "Show version") do
puts OptionParser::Version.join('.')
@@ -28,12 +51,25 @@
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
-end.parse!
+end
+begin
+opt.parse!
+rescue OptionParser::InvalidOption=>e
+ $stderr.puts e
+ $stderr.puts opt
+ exit
+end
+
+if using_math
+ $stderr.puts "Using Math extensions."
+ require 'maruku/ext/math'
+end
+
#p ARGV
#p MaRuKu::Globals
inputs =
# If we are given filenames, convert each file
@@ -52,50 +88,60 @@
end
inputs.each do |f, input|
# create Maruku
- doc = Maruku.new(input, {:on_error=>:warning})
+ params = {}
+ params[:on_error] = break_on_error ? :raise : :warning
- out=""; prefix = "?"
+ t = Time.now
+ doc = Maruku.new(input, params)
+ $stderr.puts "Parsing in %.2f seconds." % (Time.now-t)
+
+ out=""; suffix = "?"
+ t = Time.now
case export
when :html
- prefix='html'
+ suffix = using_mathml ? 'xhtml' : 'html'
out = doc.to_html_document( {:indent => -1})
when :html_frag
- prefix='html_frag'
+ suffix='html_frag'
out = doc.to_html( {:indent => -1})
when :pdf, :tex
- prefix='tex'
+ suffix='tex'
out = doc.to_latex_document
when :tex_frag
- prefix='html_frag'
+ suffix='html_frag'
out = doc.to_latex
when :inspect
- prefix='.txt'
+ suffix='.txt'
out = doc.inspect
when :markdown
- prefix='pretty_md'
+ suffix='pretty_md'
out = doc.to_markdown
end
+ $stderr.puts "Rendering in %.2f seconds." % (Time.now-t)
# write to file or stdout
if f
- dir = File.dirname(f)
- job = File.join(dir, File.basename(f, File.extname(f)))
- filename = job + "." + prefix
-
- $stderr.puts "Writing to #{filename}"
- File.open(filename,'w') do |f| f.puts out end
+ if not output_file
+ dir = File.dirname(f)
+ job = File.join(dir, File.basename(f, File.extname(f)))
+ output_file = job + "." + suffix
+ end
+
+ $stderr.puts "Writing to #{output_file}"
+ File.open(output_file,'w') do |f| f.puts out end
+
if export == :pdf
cmd = "pdflatex '#{job}' -interaction=nonstopmode "+
"'-output-directory=#{dir}' "
# run twice for cross references
system cmd
system cmd
end
else # write to stdout
- $stdout.write out
+ $stdout.puts out
end
end
-
\ No newline at end of file
+