mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-02-05 21:50:02 +00:00
Update BibTeX parser to use later fork of library
https://github.com/ORCID/bibtexParseJs
This commit is contained in:
parent
7e7ecbe7a5
commit
f863acf8ac
0
plugins/tiddlywiki/bibtex/files/LICENSE
Executable file → Normal file
0
plugins/tiddlywiki/bibtex/files/LICENSE
Executable file → Normal file
0
plugins/tiddlywiki/bibtex/files/README.md
Executable file → Normal file
0
plugins/tiddlywiki/bibtex/files/README.md
Executable file → Normal file
56
plugins/tiddlywiki/bibtex/files/bibtexParse.js
Executable file → Normal file
56
plugins/tiddlywiki/bibtex/files/bibtexParse.js
Executable file → Normal file
@ -1,9 +1,12 @@
|
|||||||
/* start bibtexParse 0.0.22 */
|
/* start bibtexParse 0.0.24 */
|
||||||
|
|
||||||
//Original work by Henrik Muehe (c) 2010
|
//Original work by Henrik Muehe (c) 2010
|
||||||
//
|
//
|
||||||
//CommonJS port by Mikola Lysenko 2013
|
//CommonJS port by Mikola Lysenko 2013
|
||||||
//
|
//
|
||||||
|
//Choice of compact (default) or pretty output from toBibtex:
|
||||||
|
// Nick Bailey, 2017.
|
||||||
|
//
|
||||||
//Port to Browser lib by ORCID / RCPETERS
|
//Port to Browser lib by ORCID / RCPETERS
|
||||||
//
|
//
|
||||||
//Issues:
|
//Issues:
|
||||||
@ -52,8 +55,8 @@
|
|||||||
if (this.input.substring(this.pos, this.pos + s.length) == s) {
|
if (this.input.substring(this.pos, this.pos + s.length) == s) {
|
||||||
this.pos += s.length;
|
this.pos += s.length;
|
||||||
} else {
|
} else {
|
||||||
throw "Token mismatch, expected " + s + ", found "
|
throw TypeError("Token mismatch: match", "expected " + s + ", found "
|
||||||
+ this.input.substring(this.pos);
|
+ this.input.substring(this.pos));
|
||||||
};
|
};
|
||||||
this.skipWhitespace(canCommentOut);
|
this.skipWhitespace(canCommentOut);
|
||||||
};
|
};
|
||||||
@ -112,7 +115,7 @@
|
|||||||
} else if (this.input[this.pos] == '{') {
|
} else if (this.input[this.pos] == '{') {
|
||||||
bracecount++;
|
bracecount++;
|
||||||
} else if (this.pos >= this.input.length - 1) {
|
} else if (this.pos >= this.input.length - 1) {
|
||||||
throw "Unterminated value";
|
throw TypeError("Unterminated value: value_braces");
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
if (this.input[this.pos] == '\\' && escaped == false)
|
if (this.input[this.pos] == '\\' && escaped == false)
|
||||||
@ -133,7 +136,7 @@
|
|||||||
if (this.input[this.pos] == '}')
|
if (this.input[this.pos] == '}')
|
||||||
brcktCnt--;
|
brcktCnt--;
|
||||||
if (this.pos >= this.input.length - 1) {
|
if (this.pos >= this.input.length - 1) {
|
||||||
throw "Unterminated value:" + this.input.substring(start);
|
throw TypeError("Unterminated value: value_comment", + this.input.substring(start));
|
||||||
};
|
};
|
||||||
this.pos++;
|
this.pos++;
|
||||||
};
|
};
|
||||||
@ -151,7 +154,7 @@
|
|||||||
this.match('"', false);
|
this.match('"', false);
|
||||||
return this.input.substring(start, end);
|
return this.input.substring(start, end);
|
||||||
} else if (this.pos >= this.input.length - 1) {
|
} else if (this.pos >= this.input.length - 1) {
|
||||||
throw "Unterminated value:" + this.input.substring(start);
|
throw TypeError("Unterminated value: value_quotes", this.input.substring(start));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (this.input[this.pos] == '\\' && escaped == false)
|
if (this.input[this.pos] == '\\' && escaped == false)
|
||||||
@ -175,7 +178,7 @@
|
|||||||
else if (this.months.indexOf(k.toLowerCase()) >= 0)
|
else if (this.months.indexOf(k.toLowerCase()) >= 0)
|
||||||
return k.toLowerCase();
|
return k.toLowerCase();
|
||||||
else
|
else
|
||||||
throw "Value expected:" + this.input.substring(start) + ' for key: ' + k;
|
throw "Value expected: single_value" + this.input.substring(start) + ' for key: ' + k;
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -194,7 +197,7 @@
|
|||||||
var start = this.pos;
|
var start = this.pos;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (this.pos >= this.input.length) {
|
if (this.pos >= this.input.length) {
|
||||||
throw "Runaway key";
|
throw TypeError("Runaway key: key");
|
||||||
};
|
};
|
||||||
// а-яА-Я is Cyrillic
|
// а-яА-Я is Cyrillic
|
||||||
//console.log(this.input[this.pos]);
|
//console.log(this.input[this.pos]);
|
||||||
@ -216,10 +219,11 @@
|
|||||||
if (this.tryMatch("=")) {
|
if (this.tryMatch("=")) {
|
||||||
this.match("=");
|
this.match("=");
|
||||||
var val = this.value();
|
var val = this.value();
|
||||||
|
key = key.trim()
|
||||||
return [ key, val ];
|
return [ key, val ];
|
||||||
} else {
|
} else {
|
||||||
throw "... = value expected, equals sign missing:"
|
throw TypeError("Value expected, equals sign missing: key_equals_value",
|
||||||
+ this.input.substring(this.pos);
|
this.input.substring(this.pos));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -289,11 +293,11 @@
|
|||||||
while (this.matchAt()) {
|
while (this.matchAt()) {
|
||||||
var d = this.directive();
|
var d = this.directive();
|
||||||
this.match("{");
|
this.match("{");
|
||||||
if (d == "@STRING") {
|
if (d.toUpperCase() == "@STRING") {
|
||||||
this.string();
|
this.string();
|
||||||
} else if (d == "@PREAMBLE") {
|
} else if (d.toUpperCase() == "@PREAMBLE") {
|
||||||
this.preamble();
|
this.preamble();
|
||||||
} else if (d == "@COMMENT") {
|
} else if (d.toUpperCase() == "@COMMENT") {
|
||||||
this.comment();
|
this.comment();
|
||||||
} else {
|
} else {
|
||||||
this.entry(d);
|
this.entry(d);
|
||||||
@ -313,25 +317,37 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* added during hackathon don't hate on me */
|
/* added during hackathon don't hate on me */
|
||||||
exports.toBibtex = function(json) {
|
/* Increased the amount of white-space to make entries
|
||||||
|
* more attractive to humans. Pass compact as false
|
||||||
|
* to enable */
|
||||||
|
exports.toBibtex = function(json, compact) {
|
||||||
|
if (compact === undefined) compact = true;
|
||||||
var out = '';
|
var out = '';
|
||||||
|
|
||||||
|
var entrysep = ',';
|
||||||
|
var indent = '';
|
||||||
|
if (!compact) {
|
||||||
|
entrysep = ',\n';
|
||||||
|
indent = ' ';
|
||||||
|
}
|
||||||
for ( var i in json) {
|
for ( var i in json) {
|
||||||
out += "@" + json[i].entryType;
|
out += "@" + json[i].entryType;
|
||||||
out += '{';
|
out += '{';
|
||||||
if (json[i].citationKey)
|
if (json[i].citationKey)
|
||||||
out += json[i].citationKey + ', ';
|
out += json[i].citationKey + entrysep;
|
||||||
if (json[i].entry)
|
if (json[i].entry)
|
||||||
out += json[i].entry ;
|
out += json[i].entry ;
|
||||||
if (json[i].entryTags) {
|
if (json[i].entryTags) {
|
||||||
var tags = '';
|
var tags = indent;
|
||||||
for (var jdx in json[i].entryTags) {
|
for (var jdx in json[i].entryTags) {
|
||||||
if (tags.length != 0)
|
if (tags.trim().length != 0)
|
||||||
tags += ', ';
|
tags += entrysep + indent;
|
||||||
tags += jdx + '= {' + json[i].entryTags[jdx] + '}';
|
tags += jdx + (compact ? '={' : ' = {') +
|
||||||
|
json[i].entryTags[jdx] + '}';
|
||||||
}
|
}
|
||||||
out += tags;
|
out += tags;
|
||||||
}
|
}
|
||||||
out += '}\n\n';
|
out += compact ? '}\n' : '\n}\n\n';
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user