2016-10-18 17:00:01 +00:00
|
|
|
/*\
|
2018-05-15 13:02:27 +00:00
|
|
|
title: $:/plugins/tiddlywiki/bibtex/deserializer.js
|
2016-10-18 17:00:01 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: tiddlerdeserializer
|
|
|
|
|
|
|
|
XLSX file deserializer
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var bibtexParse = require("$:/plugins/tiddlywiki/bibtex/bibtexParse.js");
|
|
|
|
|
|
|
|
/*
|
|
|
|
Parse an XLSX file into tiddlers
|
|
|
|
*/
|
|
|
|
exports["application/x-bibtex"] = function(text,fields) {
|
|
|
|
var data,
|
|
|
|
results = [];
|
|
|
|
// Parse the text
|
|
|
|
try {
|
|
|
|
data = bibtexParse.toJSON(text)
|
|
|
|
} catch(ex) {
|
|
|
|
data = ex.toString();
|
|
|
|
}
|
|
|
|
if(typeof data === "string") {
|
|
|
|
return [{
|
2021-04-04 10:25:39 +00:00
|
|
|
title: "BibTeX import error",
|
|
|
|
text: data
|
2016-10-18 17:00:01 +00:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
// Convert each entry
|
|
|
|
$tw.utils.each(data,function(entry) {
|
|
|
|
var fields = {
|
|
|
|
title: entry.citationKey,
|
|
|
|
"bibtex-entry-type": entry.entryType
|
|
|
|
};
|
|
|
|
$tw.utils.each(entry.entryTags,function(value,name) {
|
2021-04-07 16:43:41 +00:00
|
|
|
fields["bibtex-" + name.toLowerCase()] = value;
|
2016-10-18 17:00:01 +00:00
|
|
|
});
|
|
|
|
results.push(fields);
|
|
|
|
});
|
|
|
|
// Return the output tiddlers
|
|
|
|
return results;
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|