JSDependencies
Documenter.Utilities.JSDependencies — ModuleProvides an API to programmatically construct a RequireJS script.
Documenter.Utilities.JSDependencies.RemoteLibrary — Typestruct RemoteLibraryDeclares a remote JS dependency that should be declared in the RequireJS configuration shim.
Fields
name: a unique name for the dependency, used to refer to it in other dependencies and snippetsurl: full remote URL from where the dependency can be loaded fromdeps: a list of the library's dependencies (becomes thedepsconfiguration in the RequireJS shim)exports: sets theexportsconfig in the resulting RequireJS shim
Constructors
RemoteLibrary(name::AbstractString, url::AbstractString; deps=String[], exports=nothing)Documenter.Utilities.JSDependencies.RequireJS — Typestruct RequireJSDeclares a single RequireJS configuration/app file.
Fields
libraries: a dictionary ofRemoteLibrarydeclarations (keys are the library names)snippets: a list of JS snippets (Snippet)
Constructors
RequireJS(libraries::AbstractVector{RemoteLibrary}, snippets::AbstractVector{Snippet} = Snippet[])API
- The
push!function can be used to add additional libraries and snippets.
Documenter.Utilities.JSDependencies.Snippet — Typestruct SnippetDeclares a JS code snipped that should be loaded with RequireJS. This gets wrapped in require([deps...], function(args...) {script...}) in the output.
Fields
deps: names of theRemoteLibrarydependencies of the snippetargs: the arguments of the callback function, corresponding to the library objects of the dependencies, in the order ofdepsjs: the JS code of the function that gets used as the function body of the callback
Constructors
Snippet(deps::AbstractVector, args::AbstractVector, js::AbstractString)Documenter.Utilities.JSDependencies.jsescape — MethodReplaces some of the characters in the string with escape sequences so that the strings would be valid JS string literals, as per the ECMAScript® 2017 standard. Note that it always escapes both potential " and ' closing quotes.
Documenter.Utilities.JSDependencies.json_jsescape — Methodjson_jsescape(args...)Call JSON.json(args...) to generate a String of JSON, but then also escape two Unicode characters to get valid JS (since JSON is not a JS subset).
Technically, starting with ECMAScript® 2019 (10th edition), this is no longer necessary. The JS standard was changed in a way that all valid JSON is also valid JS.
Documenter.Utilities.JSDependencies.parse_snippet — Functionparse_snippet(filename::AbstractString) -> Snippet
parse_snippet(io::IO) -> SnippetParses a JS snippet file into a Snippet object.
Format
The first few lines are parsed to get the dependencies and argument variable names of the snippet. They need to match ^//\s*([a-z]+): (i.e. start with //, optional whitespace, a lowercase identifier, and a colon). Once the parser hits a line that does not match that pattern, it will assume that it and all the following lines are the actual script.
Only lowercase letters are allowed in the identifiers. Currently only libraries and arguments are actually parsed and lines with other syntactically valid identifiers are ignored. For libraries and arguments, the value (after the colon) must be a comma separated list.
A valid snippet file would look like the following. Note that the list of arguments can be shorter than the list of dependencies.
// libraries: jquery, highlight, highlight-julia, highlight-julia-repl
// arguments: $, hljs
// Initialize the highlight.js highlighter
$(document).ready(function() {
hljs.initHighlighting();
})Documenter.Utilities.JSDependencies.verify — Methodverify(r::RequireJS; verbose=false) -> BoolChecks that none of the dependencies are missing (returns false if some are). If verbose is set to true, it will also log an error with the missing dependency.
Documenter.Utilities.JSDependencies.writejs — Functionwritejs(io::IO, r::RequireJS)
writejs(filename::AbstractString, r::RequireJS)Writes out the RequireJS object as a valid JS that can be loaded with a <script> tag, either into a stream or a file. It will contain all the configuration and snippets.