This repository has been archived by the owner on Aug 20, 2020. It is now read-only.
forked from rsdoiel/bibtex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bibscrape.js
59 lines (52 loc) · 1.89 KB
/
bibscrape.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* bibmerge.js binds the form elements to access the bibtex object implemented with GopherJS
*/
(function (window, document) {
'use strict';
var inputTextArea = document.getElementById("input-source"),
outputTextArea = document.getElementById("output-bibtex"),
entryType = document.getElementById("entry-type"),
entrySeparator = document.getElementById("entry-separator"),
submitButton = document.getElementById("scrape"),
cmdExample = document.getElementById("cmd-example-bibtex");
function splitEntries(src, sep) {
var re,
i = 0;
re = new RegExp(sep, "g");
return src.split(re);
}
submitButton.addEventListener("click", function (evt) {
var scrape = bibtex.New(),
cmd = [],
out = [],
separator = "\n\n",
entry_type = "pseudo",
src = "",
entries = [],
entry = "";
// Update the default values if needed
if (entrySeparator.value != undefined && entrySeparator.value !== "") {
separator = entrySeparator.value;
}
if (entryType.value != undefined && entryType.value !== "") {
entry_type = entryType.value;
}
src = inputTextArea.value;
entries = splitEntries(src, separator)
entries.forEach(function(item, i) {
if (item.trim() !== "") {
out.push(scrape.Scrape(item, entry_type, "pseudo_id_" + i));
}
});
outputTextArea.value = out.join("\n\n")
if (cmdExample) {
cmd.push("bibscrape");
cmd.push("-t " + entry_type);
cmd.push("-e '" + separator + "'");
cmd.push("-k");
cmd.push("example.txt");
cmd.push("> example.bib");
cmdExample.value = cmd.join(" ");
}
});
}(window, document));