Allow executing non-remote JS for KaTeX
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
parent
c197a45540
commit
06ee998d54
21
convert.rb
21
convert.rb
|
@ -3,6 +3,7 @@ require "nokogiri"
|
|||
require "net/http"
|
||||
require "json"
|
||||
require "cgi"
|
||||
require "optparse"
|
||||
|
||||
class KatexRenderer
|
||||
def initialize(source)
|
||||
|
@ -34,10 +35,26 @@ class KatexRenderer
|
|||
end
|
||||
end
|
||||
|
||||
# Provided via this project's Gemfile
|
||||
ExecJS.runtime = ExecJS::Runtimes::Duktape
|
||||
|
||||
renderer = KatexRenderer.new(Net::HTTP.get(URI("https://static.danilafe.com/katex/katex.min.js")))
|
||||
files = ARGV[0..-1]
|
||||
katex = nil
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: convert.rb [options]"
|
||||
|
||||
opts.on("--katex-js-file=FILE", "Use the given KaTeX JS file to process LaTeX") do |f|
|
||||
katex = f
|
||||
end
|
||||
end.parse!
|
||||
files = ARGV
|
||||
|
||||
if katex
|
||||
katex = File.read(katex)
|
||||
else
|
||||
katex = Net::HTTP.get(URI("https://static.danilafe.com/katex/katex.min.js"))
|
||||
end
|
||||
|
||||
renderer = KatexRenderer.new(katex)
|
||||
files.each do |file|
|
||||
puts "Rendering file: #{file}"
|
||||
document = Nokogiri::HTML.parse(File.open(file))
|
||||
|
|
Loading…
Reference in New Issue
Block a user