Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable MathJax functionality #11

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/PlotlyKaleido.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ end

const P = Pipes()

const _mathjax_url_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax"
const _mathjax_last_version = v"2.7.9"

kill_kaleido() = is_running() && kill(P.proc)

is_running() = isdefined(P, :proc) && isopen(P.stdin) && process_running(P.proc)

restart(;kwargs...) = (kill_kaleido(); sleep(0.1); start(;kwargs...))

function start(;plotly_version = missing, kwargs...)
function start(;plotly_version = missing,
mathjax = missing, mathjax_version::VersionNumber = _mathjax_last_version,
kwargs...)
is_running() && return
cmd = joinpath(Kaleido_jll.artifact_dir, "kaleido" * (Sys.iswindows() ? ".cmd" : ""))
basic_cmds = [cmd, "plotly"]
Expand All @@ -39,6 +44,21 @@ function start(;plotly_version = missing, kwargs...)
kwargs...
)
end
if !(mathjax === missing)
if mathjax_version > v"2.7.9"
error("The given mathjax version $(mathjax_version) is greater than the last supported version of $(_mathjax_last_version).")
end
BeastyBlacksmith marked this conversation as resolved.
Show resolved Hide resolved
if mathjax isa Bool && mathjax
push!(chromium_flags, "--mathjax=$(_mathjax_url_path)/$(mathjax_version)/MathJax.js")
elseif mathjax isa String
# We expect the keyword argument to be a valid URL or similar, else error "Kaleido startup failed with code 1".
push!(chromium_flags, "--mathjax=$(mathjax)")
else
@warn """The value of the provided argument
mathjax=$(mathjax)
is neither a Bool nor a String and has been ignored."""
end
end
# Taken inspiration from https://github.com/plotly/Kaleido/blob/3b590b563385567f257db8ff27adae1adf77821f/repos/kaleido/py/kaleido/scopes/base.py#L116-L141
user_flags = String[]
for (k,v) in pairs(extra_flags)
Expand Down