diff --git a/src/html/HTMLWriter.jl b/src/html/HTMLWriter.jl index c5b2aa8e3f..15e0084ccc 100644 --- a/src/html/HTMLWriter.jl +++ b/src/html/HTMLWriter.jl @@ -99,9 +99,10 @@ struct HTMLAsset class :: Symbol uri :: String islocal :: Bool + load_early :: Bool attributes::Dict{Symbol, String} - function HTMLAsset(class::Symbol, uri::String, islocal::Bool, attributes::Dict{Symbol, String}=Dict{Symbol,String}()) + function HTMLAsset(class::Symbol, uri::String, islocal::Bool, load_early::Bool=false, attributes::Dict{Symbol, String}=Dict{Symbol,String}()) if !islocal && match(r"^https?://", uri) === nothing error("Remote asset URL must start with http:// or https://") end @@ -109,10 +110,11 @@ struct HTMLAsset @error("Local asset should not have an absolute URI: $uri") end class in [:ico, :css, :js] || error("Unrecognised asset class $class for `$(uri)`") - new(class, uri, islocal, attributes) + new(class, uri, islocal, load_early, attributes) end end + """ asset(uri) @@ -133,6 +135,9 @@ elements in `
`, respectively. relative to the documentation source directory (conventionally `src/`). This can be useful when it is necessary to override the asset class of a local asset. +**`load_early`** can be used to load the JS before requirejs when the script +is not Asynchronous Module Definition (AMD) compatible. + # Usage ```julia @@ -148,7 +153,7 @@ Documenter.HTML(assets = [ ]) ``` """ -function asset(uri; class = nothing, islocal=false, attributes=Dict{Symbol,String}()) +function asset(uri; class = nothing, islocal=false, load_early=false, attributes=Dict{Symbol,String}()) if class === nothing class = assetclass(uri) (class === nothing) && error(""" @@ -156,7 +161,7 @@ function asset(uri; class = nothing, islocal=false, attributes=Dict{Symbol,Strin It can be set explicitly with the `class` keyword argument. """) end - HTMLAsset(class, uri, islocal, attributes) + HTMLAsset(class, uri, islocal, load_early, attributes) end function assetclass(uri) @@ -1005,6 +1010,10 @@ function render_head(ctx, navnode) end, script("documenterBaseURL=\"$(relhref(src, "."))\""), + + # Custom user-provided assets which are loaded early for non-AMD compatible modules. + asset_links(src, filter(x -> x.load_early, ctx.settings.assets)), + script[ :src => RD.requirejs_cdn, Symbol("data-main") => relhref(src, ctx.documenter_js) @@ -1026,8 +1035,9 @@ function render_head(ctx, navnode) return e end, script[:src => relhref(src, ctx.themeswap_js)], + # Custom user-provided assets. - asset_links(src, ctx.settings.assets), + asset_links(src, filter(x -> !x.load_early, ctx.settings.assets)) ) end diff --git a/test/examples/make.jl b/test/examples/make.jl index c68ac357cb..ce9c5a62e7 100644 --- a/test/examples/make.jl +++ b/test/examples/make.jl @@ -275,7 +275,7 @@ function html_doc( "assets/favicon.ico", "assets/custom.css", asset("https://example.com/resource.js"), - asset("http://example.com/fonts?param=foo", class=:css), + asset("http://example.com/fonts?param=foo", class=:css, load_early=true), asset("https://fonts.googleapis.com/css?family=Nanum+Brush+Script&display=swap", class=:css), ], prettyurls = true,