document object. In the Drafts scripting environment, is there any way to initialise this document object? Ideally I’d like to set it to the current draft, so I can interact with it using the DOM methods. Is this possible?
I wouldn’t have thought so – the DOM API is an interface to parsed HTML pages in web browsers.
The quickest way to find out is to evaluate the expression:
Which returns the names of the top level objects available in the global namespace of the JS interpreter.
If you do that in a Chrome or Safari console, you will see all of the DOM objects (Window and Document etc etc)
If you do it in Drafts, 1Writer, Taskpaper, or the OmniJS of Omni Applications, you will see very different (application-specific) lists of available objects.
For a fuller picture, see for example
or, more helpfully:
Editorial does, of course, include a browser, and there is a method for evaluating JS snippets in, but not, as far as I recall, a way of passing data to those snippets at run time, other than using a fairly fiddly mechanism of loading quoted JSON from the file system.