1 | import bibtexParse from "bibtex-parse-js";
|
2 |
|
3 | export default function(dom, data) {
|
4 | let el = dom.querySelector('script[type="text/bibliography"]');
|
5 | let citations = [];
|
6 | let bibliography = {};
|
7 |
|
8 | if (el) {
|
9 | let rawBib = el.textContent;
|
10 | let parsed = bibtexParse.toJSON(rawBib);
|
11 | if(parsed) {
|
12 | parsed.forEach(e => {
|
13 | for (var k in e.entryTags){
|
14 | var val = e.entryTags[k];
|
15 | val = val.replace(/[\t\n ]+/g, " ");
|
16 | val = val.replace(/{\\["^`\.'acu~Hvs]( )?([a-zA-Z])}/g,
|
17 | (full, x, char) => char);
|
18 | val = val.replace(/{\\([a-zA-Z])}/g,
|
19 | (full, char) => char);
|
20 | e.entryTags[k] = val;
|
21 | }
|
22 | bibliography[e.citationKey] = e.entryTags;
|
23 | bibliography[e.citationKey].type = e.entryType;
|
24 | });
|
25 | }
|
26 |
|
27 |
|
28 | var citeTags = [].slice.apply(dom.querySelectorAll("dt-cite"));
|
29 | citeTags.forEach(el => {
|
30 | let key = el.getAttribute("key");
|
31 | if (key) {
|
32 | let citationKeys = key.split(",");
|
33 | citationKeys.forEach(key => {
|
34 | if (citations.indexOf(key) == -1){
|
35 | citations.push(key);
|
36 | if (!(key in bibliography)){
|
37 | console.warn("No bibliography entry found for: " + key);
|
38 | }
|
39 | }
|
40 | });
|
41 | }
|
42 | });
|
43 | }
|
44 | data.bibliography = bibliography;
|
45 | data.citations = citations;
|
46 | }
|