1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-04 23:39:57 +00:00
TiddlyWiki5/plugins/tiddlywiki/bibtex/deserializer.js

51 lines
995 B
JavaScript
Raw Normal View History

2016-10-18 17:00:01 +00:00
/*\
title: $:/plugins/tiddlywiki/bibtex/deserializer.js
2016-10-18 17:00:01 +00:00
type: application/javascript
module-type: tiddlerdeserializer
2022-12-16 17:41:05 +00:00
BibTeX file deserializer
2016-10-18 17:00:01 +00:00
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var bibtexParse = require("$:/plugins/tiddlywiki/bibtex/bibtexParse.js");
/*
2022-12-16 17:41:05 +00:00
Parse an BibTeX file into tiddlers
2016-10-18 17:00:01 +00:00
*/
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 [{
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) {
fields["bibtex-" + name.toLowerCase()] = value;
2016-10-18 17:00:01 +00:00
});
results.push(fields);
});
// Return the output tiddlers
return results;
};
})();