From 4d593dc5b1377a442aa2cbd945e72d9f6b81546b Mon Sep 17 00:00:00 2001 From: ianqsong Date: Sun, 4 Oct 2020 13:00:24 +0800 Subject: [PATCH 1/5] add an arg. for mathjax cdn --- src/Writers/HTMLWriter.jl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Writers/HTMLWriter.jl b/src/Writers/HTMLWriter.jl index c0c154f121..aaee476143 100644 --- a/src/Writers/HTMLWriter.jl +++ b/src/Writers/HTMLWriter.jl @@ -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 @@ -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), @@ -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 @@ -508,10 +510,11 @@ module RD """ )) end - function mathengine!(r::RequireJS, engine::MathJax2) + function mathengine!(r::RequireJS, engine::MathJax2; + cdn::String = "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"], @@ -520,14 +523,15 @@ module RD """ )) end - function mathengine!(r::RequireJS, engine::MathJax3) + function mathengine!(r::RequireJS, engine::MathJax3; + cdn::String = "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); })(); @@ -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) + typeof(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) From a192080b3f055e0a64ed03217071a1a572bdb40c Mon Sep 17 00:00:00 2001 From: ianqsong Date: Sun, 4 Oct 2020 13:58:38 +0800 Subject: [PATCH 2/5] fix --- src/Writers/HTMLWriter.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Writers/HTMLWriter.jl b/src/Writers/HTMLWriter.jl index aaee476143..fbf336f28e 100644 --- a/src/Writers/HTMLWriter.jl +++ b/src/Writers/HTMLWriter.jl @@ -510,8 +510,8 @@ module RD """ )) end - function mathengine!(r::RequireJS, engine::MathJax2; - cdn::String = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_HTML") + function mathengine!(r::RequireJS, engine::MathJax2, mathjaxcdn::String) + cdn = isempty(mathjaxcdn) ? "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_HTML" : mathjaxcdn push!(r, RemoteLibrary( "mathjax", cdn, @@ -523,8 +523,8 @@ module RD """ )) end - function mathengine!(r::RequireJS, engine::MathJax3; - cdn::String = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.0.5/es5/tex-svg.js") + function mathengine!(r::RequireJS, engine::MathJax3, mathjaxcdn::String) + cdn = isempty(mathjaxcdn) ? "https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.0.5/es5/tex-svg.js" : mathjaxcdn push!(r, Snippet([], [], """ window.MathJax = $(json_jsescape(engine.config, 2)); From 139dea7afb26b823596f181e995cc2b863ed9940 Mon Sep 17 00:00:00 2001 From: ianqsong Date: Sun, 4 Oct 2020 16:38:01 +0800 Subject: [PATCH 3/5] minor --- src/Writers/HTMLWriter.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Writers/HTMLWriter.jl b/src/Writers/HTMLWriter.jl index fbf336f28e..8ec5dc0a22 100644 --- a/src/Writers/HTMLWriter.jl +++ b/src/Writers/HTMLWriter.jl @@ -634,7 +634,7 @@ function render(doc::Documents.Document, settings::HTML=HTML()) r = JSDependencies.RequireJS([ RD.jquery, RD.jqueryui, RD.headroom, RD.headroom_jquery, ]) - typeof(settings.mathengine) == KaTeX ? 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")) From 4e3d69765beaa402ef5114a809ebb17378296eaa Mon Sep 17 00:00:00 2001 From: ianqsong Date: Sun, 4 Oct 2020 16:48:12 +0800 Subject: [PATCH 4/5] review --- src/Writers/HTMLWriter.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Writers/HTMLWriter.jl b/src/Writers/HTMLWriter.jl index 8ec5dc0a22..c1d989e7f8 100644 --- a/src/Writers/HTMLWriter.jl +++ b/src/Writers/HTMLWriter.jl @@ -510,8 +510,8 @@ module RD """ )) end - function mathengine!(r::RequireJS, engine::MathJax2, mathjaxcdn::String) - cdn = isempty(mathjaxcdn) ? "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js?config=TeX-AMS_HTML" : mathjaxcdn + 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", cdn, @@ -523,8 +523,8 @@ module RD """ )) end - function mathengine!(r::RequireJS, engine::MathJax3, mathjaxcdn::String) - cdn = isempty(mathjaxcdn) ? "https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.0.5/es5/tex-svg.js" : mathjaxcdn + 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)); From 095f50259168c5140d351e0be2f7f405f22eadeb Mon Sep 17 00:00:00 2001 From: ianqsong Date: Sun, 4 Oct 2020 13:00:24 +0800 Subject: [PATCH 5/5] add an arg. for mathjax cdn (squash) --- src/Writers/HTMLWriter.jl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Writers/HTMLWriter.jl b/src/Writers/HTMLWriter.jl index c0c154f121..c1d989e7f8 100644 --- a/src/Writers/HTMLWriter.jl +++ b/src/Writers/HTMLWriter.jl @@ -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 @@ -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), @@ -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 @@ -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"], @@ -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); })(); @@ -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)