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 "net/http"
|
||||||
require "json"
|
require "json"
|
||||||
require "cgi"
|
require "cgi"
|
||||||
|
require "optparse"
|
||||||
|
|
||||||
class KatexRenderer
|
class KatexRenderer
|
||||||
def initialize(source)
|
def initialize(source)
|
||||||
|
@ -34,10 +35,26 @@ class KatexRenderer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Provided via this project's Gemfile
|
||||||
ExecJS.runtime = ExecJS::Runtimes::Duktape
|
ExecJS.runtime = ExecJS::Runtimes::Duktape
|
||||||
|
|
||||||
renderer = KatexRenderer.new(Net::HTTP.get(URI("https://static.danilafe.com/katex/katex.min.js")))
|
katex = nil
|
||||||
files = ARGV[0..-1]
|
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|
|
files.each do |file|
|
||||||
puts "Rendering file: #{file}"
|
puts "Rendering file: #{file}"
|
||||||
document = Nokogiri::HTML.parse(File.open(file))
|
document = Nokogiri::HTML.parse(File.open(file))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user