JSDependencies

Documenter.JSDependencies.RemoteLibraryType
struct 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 snippets
  • url: full remote URL from where the dependency can be loaded from
  • deps: a list of the library's dependencies (becomes the deps configuration in the RequireJS shim)
  • exports: sets the exports config in the resulting RequireJS shim

Constructors

RemoteLibrary(name::AbstractString, url::AbstractString; deps=String[], exports=nothing)
source
Documenter.JSDependencies.RequireJSType
struct RequireJS

Declares a single RequireJS configuration/app file.

Fields

  • libraries: a dictionary of RemoteLibrary 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.
source
Documenter.JSDependencies.SnippetType
struct 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 the RemoteLibrary dependencies of the snippet
  • args: the arguments of the callback function, corresponding to the library objects of the dependencies, in the order of deps
  • 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)
source
Documenter.JSDependencies.json_jsescapeMethod
json_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).

Note

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.

source
Documenter.JSDependencies.parse_snippetFunction
parse_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();
})
source
Documenter.JSDependencies.verifyMethod
verify(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.

source
Documenter.JSDependencies.writejsFunction
writejs(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.

source