Skip to content

Instantly share code, notes, and snippets.

@simonster
Created December 6, 2011 08:01
Show Gist options
  • Save simonster/1437304 to your computer and use it in GitHub Desktop.
Save simonster/1437304 to your computer and use it in GitHub Desktop.
CSL JSON translator (WIP)
{
"translatorID": "bc03b4fe-436d-4a1f-ba59-de4d2d7a63f7",
"label": "CSL JSON",
"creator": "Simon Kornblith",
"target": "json",
"minVersion": "3.0b3",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 3,
"browserSupport": "gcs",
"lastUpdated": "2011-09-25 20:49:56"
}
var parsedData;
function detectImport() {
var str, data = [];
while((str = Z.read(32768)) !== false) {
data.push(str)
}
try {
var parsedData = JSON.parse(str);
return !!parsedData[0].itemID;
} catch(e) {}
return false;
}
function doImport() {
for(var i=0; i<parsedData.length; i++) {
var item = new Z.Item();
ZU.itemFromCSLJSON(parsedData[i], item);
item.complete();
}
}
function doExport() {
var item, data = [];
while(item = Z.nextItem()) data.push(ZU.itemToCSLJSON(item));
Z.write(JSON.stringify(data, null, "\t"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment