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

add an argument for mathjax cdn #1429

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Writers/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ struct HTML <: Documenter.Writer
sidebar_sitename :: Bool
highlights :: Vector{String}
mathengine :: Union{MathEngine,Nothing}
mathjaxcdn :: String
footer :: Union{Markdown.MD, Nothing}
lang :: String

Expand All @@ -387,6 +388,7 @@ struct HTML <: Documenter.Writer
sidebar_sitename :: Bool = true,
highlights :: Vector{String} = String[],
mathengine :: Union{MathEngine,Nothing} = KaTeX(),
mathjaxcdn :: String = "",
footer :: Union{String, Nothing} = "Powered by [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl) and the [Julia Programming Language](https://julialang.org/).",
# deprecated keywords
edit_branch :: Union{String, Nothing, Default} = Default(nothing),
Expand Down Expand Up @@ -418,7 +420,7 @@ struct HTML <: Documenter.Writer
end
isa(edit_link, Default) && (edit_link = edit_link[])
new(prettyurls, disable_git, edit_link, canonical, assets, analytics,
collapselevel, sidebar_sitename, highlights, mathengine, footer, lang)
collapselevel, sidebar_sitename, highlights, mathengine, mathjaxcdn, footer, lang)
end
end

Expand Down Expand Up @@ -508,10 +510,11 @@ module RD
"""
))
end
function mathengine!(r::RequireJS, engine::MathJax2)
function mathengine!(r::RequireJS, engine::MathJax2, cdn::String)
isempty(cdn) && cdn = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_HTML"
push!(r, RemoteLibrary(
"mathjax",
"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_HTML",
cdn,
exports = "MathJax"
))
push!(r, Snippet(["mathjax"], ["MathJax"],
Expand All @@ -520,14 +523,15 @@ module RD
"""
))
end
function mathengine!(r::RequireJS, engine::MathJax3)
function mathengine!(r::RequireJS, engine::MathJax3, cdn::String)
isempty(cdn) && cdn = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.0.5/es5/tex-svg.js"
push!(r, Snippet([], [],
"""
window.MathJax = $(json_jsescape(engine.config, 2));

(function () {
var script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.0.5/es5/tex-svg.js';
script.src = $cdn;
script.async = true;
document.head.appendChild(script);
})();
Expand Down Expand Up @@ -630,7 +634,8 @@ function render(doc::Documents.Document, settings::HTML=HTML())
r = JSDependencies.RequireJS([
RD.jquery, RD.jqueryui, RD.headroom, RD.headroom_jquery,
])
RD.mathengine!(r, settings.mathengine)
isa(settings.mathengine, KaTeX) ? RD.mathengine!(r, settings.mathengine) :
RD.mathengine!(r, settings.mathengine, settings.mathjaxcdn)
RD.highlightjs!(r, settings.highlights)
for filename in readdir(joinpath(ASSETS, "js"))
path = joinpath(ASSETS, "js", filename)
Expand Down