Translators: saving portions of a DOM as attachments

16 views
Skip to first unread message

Frank Bennett

unread,
Mar 23, 2018, 9:45:00 AM3/23/18
to zotero-dev
In Zotero 4.0, I was able to access importFromDocument() via a translator to save portions of a page in a fresh document generated internally. I used it mostly to create clean, readable primary documents from legal information sites.

It looks like that is not currently possible in 5.0, and I'm curious whether there is a plan to reintroduce this capability? It was a handy thing, and it would be great to have it back.

(If I'm mistaken and this is still possible, that would of course be the best news of all.)

Frank

Dan Stillman

unread,
Mar 24, 2018, 1:50:38 AM3/24/18
to zoter...@googlegroups.com
Do you have an example of what you were doing?
Zotero.Attachments.importFromDocument() wouldn't (or at least shouldn't)
have been something available in translators, since that's not in the
translator sandbox, though you could (and still can) return a document
as an attachment from the translator.

The main thing that changed recently is that translators use XHR for
loading documents instead of a hidden browser, so you only have access
to the over-the-wire structure of the page, not the JS-modified page you
would get in a browser.

Frank Bennett

unread,
Mar 24, 2018, 6:49:21 AM3/24/18
to zoter...@googlegroups.com
Probably better that I describe with snippets, since the translator code is more convoluted than it should be.

The translator acquires serialized HTML from an API endpoint documented here:


The translation then builds a FOM document with createDocument(), with a base element as mentioned on importFromDocument().

The DOM object is then fed to the item in the usual way:

item.attachments.push({
  document: newDoc,
  snapshot: true
})

The document has no location.href, and I think that may be why it is stripped out. In attachments.js, there is still and attachment, but it is no longer xmlDocument, and the attachment fails.

This used to work in MLZ/Juris-M, but I seem to remember hacking on the original code to get it going. Some messy hacks that looked fragile were left behind in the 5.0 migration, that was probably one of them.

--
You received this message because you are subscribed to the Google Groups "zotero-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zotero-dev+...@googlegroups.com.
To post to this group, send email to zoter...@googlegroups.com.
Visit this group at https://groups.google.com/group/zotero-dev.
For more options, visit https://groups.google.com/d/optout.

Frank Bennett

unread,
Mar 24, 2018, 6:54:02 AM3/24/18
to zoter...@googlegroups.com
Actually, hold on. Having written that, I wonder if it would work to just and a new HTML header and footer to the acquired HTML and send it over as mine type text/html. Is there a translator incantation that would allow that?

Dan Stillman

unread,
Mar 24, 2018, 4:15:25 PM3/24/18
to zoter...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages