citeproc-js API issue: duplicate citationIDs

18 views
Skip to first unread message

Frank Bennett

unread,
May 25, 2016, 8:47:11 PM5/25/16
to zotero-dev
To build a simple no-install demo page for citeproc-js/CSL with tinyMCE, I've had to build a transaction layer to serve the purpose of Zotero's integration.js. That forced me to look carefully at the logic of DOM-to-processor transactions, and I've learned two things:

(1) It is useful to include the citationID in the return from processCitationCluster(); and

(2) When citations are addressed by citationID, and the document contains duplicate IDs due to copy-and-paste, bad things happen.

Addressing these issues has involved some small changes to processor behaviour. I don't think they will affect Zotero, but I want to reach out with a heads-up in any case, to avoid breaking things in the next release.

(1) citationID in processCitationCluster() return

The processor currently returns a two-element array. Position [0] is an info object, and position [1] is the actual update data, as an array of two-element arrays. Each update item has the target citation index at [0], and the string for insertion at [1]. For the demo, I've extended this to include the citationID at [2]. The citationID may be assigned by the processor, in which case the caller may not have a record of it, and in that case the document node must be updated to reflect the citationID registered in the processor.

The processor generates citationIDs internally when: (a) no citationID is provided on the citation object that is the first argument to processCitationCluster(); or (b) the citationID is a duplicate (see below). If the integration layer generates its own citationIDs with protection against duplicates, automatic generation of citationID will not be triggered.

(2) duplicate citationIDs

Copy-pasting within a document can create duplicate citationIDs, and this is a problem if the ID is used to address citation nodes for update in the document. To address that, I have introduced code that clones the duplicated citation object, assigns it a fresh ID, registers in citationByIndex and citationById, and taints the citation so that it will be included in the return.


An additional document-state issue that this change does not address is the possibility of pasting in an alien citation with an unknown ID---a condition that cannot occur in the simple online demo here:

    http://citeproc-js.readthedocs.io/en/latest/editor.html

For DOM-based projects like the demo page, alien citationIDs are a bridge to be crossed when we get there; but meanwhile, the fact that pasting citations across documents does not shatter things in Zotero leads me to suspect that it does not rely on citationIDs at all---I could be wrong there, though.

In any case, if there are questions or concerns about these changes, let me know!

Frank

Reply all
Reply to author
Forward
0 new messages