JSDependencies
Documenter.JSDependencies
— ModuleProvides an API to programmatically construct a RequireJS script.
Documenter.JSDependencies.RemoteLibrary
— Typestruct RemoteLibrary
Declares 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 thedeps
configuration in the RequireJS shim)exports
: sets theexports
config in the resulting RequireJS shim
Constructors
RemoteLibrary(name::AbstractString, url::AbstractString; deps=String[], exports=nothing)
Documenter.JSDependencies.RequireJS
— Typestruct RequireJS
Declares a single RequireJS configuration/app file.
Fields
libraries
: a dictionary ofRemoteLibrary
declarations (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.JSDependencies.Snippet
— Typestruct Snippet
Declares 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 theRemoteLibrary
dependencies of the snippetargs
: the arguments of the callback function, corresponding to the library objects of the dependencies, in the order ofdeps
js
: 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.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.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.JSDependencies.parse_snippet
— Functionparse_snippet(filename::AbstractString) -> Snippet
parse_snippet(io::IO) -> Snippet
Parses 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.JSDependencies.verify
— Methodverify(r::RequireJS; verbose=false) -> Bool
Checks 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.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.