Allow executing non-remote JS for KaTeX

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
Danila Fedorin 2024-05-23 21:14:49 -07:00
parent c197a45540
commit 06ee998d54

View File

@ -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))