Sha256: 97d570771ba316053837a200a6d985459c30722aa466c8327a1e4b2d6890cfab

Contents?: true

Size: 1.9 KB

Versions: 2

Compression:

Stored size: 1.9 KB

Contents

#!/usr/bin/env ruby
require "polytexnic"
require 'optparse'
require 'fileutils'

# polytexnic command-line script
# The polytexnic script converts Markdown to HTML or LaTeX
# using the PolyTeXnic HTML pipeline.

examples = %(
The polytexnic script converts Markdown to HTML or LaTeX
using the PolyTeXnic HTML pipeline.

Examples:
    polytexnic example.md example.html
    polytexnic example.md > example.html
    polytexnic < example.md > example.html
    cat example.md | polytexnic > example.html
    polytexnic -i example.md > example.html
    polytexnic -i example.md -o example.tex
    polytexnic -f tex example.md)

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: polytexnic [options]\n#{examples}\n\n"

  opts.on("-i", "--input=INPUT", "Use file input") do |infile|
    options[:infile] = infile
  end

  opts.on("-o", "--output=OUTPUT", "Use file output") do |outfile|
    options[:outfile] = outfile
  end

  opts.on("-f", "--format", "Use output format [html, tex]") do |format|
    options[:format] = format
  end
end.parse!

# Returns the file format based on extension.
# Should be 'html' or 'tex'.
def format(filename)
  puts '***********'
  puts '***********'
  puts '***********'
  puts '***********'
  puts '***********'
  p filename.split('.')
  filename.split('.').last
rescue
  nil
end

puts '$$$$$$$$$$$'
puts '$$$$$$$$$$$'
puts '$$$$$$$$$$$'
puts '$$$$$$$$$$$'
puts '$$$$$$$$$$$'
p options
if (infile = options[:infile] || ARGV.shift)
puts infile
  input = File.read(infile)
else
  input = STDIN.read
end
outfile  = options[:outfile] || ARGV.shift
puts outfile
pipeline = Polytexnic::Pipeline.new(input, article: true)
format   = options[:format] || format(outfile) || "html"
if format == "html"
  output = pipeline.to_html
elsif format == "tex"
  output = pipeline.to_polytex
else
  raise ArgumentError, "Invalid format: #{format}"
end
if outfile
  File.write(outfile, output)
else
  puts output.strip
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
polytexnic-1.6.2 bin/polytexnic
polytexnic-1.6.1 bin/polytexnic