3. add-script

add-script(script-uri, resource-uri?, charset?, type?)

Add a script XHTML element pointing to specified resource-uri to the document being edited. Moreover script file script-uri is copied to resource file resource-uri.

script-uri

The absolute or relative URI of the script file (e.g. a JavaScript™ file). A relative URI is relative to the URI of the XED script invoking command add-script.

resource-uri

The script file located at script-uri is copied to resource-uri, which must be an absolute or relative "file:" URI. A relative URI is relative to the URI of the document being edited.

Defaults to resource_dir/basename_of_script-uri. By default, resource_dir is basename_of_output_file_files. For example, if the output file is C:\temp\out.xhtml and the script file is C:\scripts\myscript.js, then resource-uri defaults to file:/C:/temp/out_files/myscript.js.

Note that the above default can be determined only when a convert step has been executed prior to the edit step. That is, unless a convert step has been executed, specifying resource-uri is required.

charset

The character encoding of the script file. Defaults to "", the empty string. Specifying "" allows to create a script HTML element not having a charset attribute.

type

The type of the script. Defaults to "text/javascript". Specifying "", the empty string, allows to create a script HTML element not having a type attribute.

Example 1: let's suppose output file is C:\temp\out.xhtml.

add-script("myscript.js");

adds:

<script src="out_files/myscript.js" type="text/javascript"></script>

Example 2:

add-script("myscript.js", "", "", "");

adds:

<script src="out_files/myscript.js"></script>

Example 3:

add-script("myscript.js", "my%20scripts/script%201.js", "UTF-8");

adds:

<script src="my%20scripts/script%201.js" charset="UTF-8" type="text/javascript"></script>