mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
i really hate this library
This commit is contained in:
parent
909cb9a768
commit
bceacab4ca
1159
package-lock.json
generated
1159
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -17,7 +17,6 @@ export default function cffToJsonPlugin() {
|
|||||||
transform: function (code, id) {
|
transform: function (code, id) {
|
||||||
if (!filter(id) || (extname(id) !== ".js" && extname(id) !== ".ts")) return;
|
if (!filter(id) || (extname(id) !== ".js" && extname(id) !== ".ts")) return;
|
||||||
const magicString = new MagicString(code);
|
const magicString = new MagicString(code);
|
||||||
const targetString = "citation: []";
|
|
||||||
|
|
||||||
// Try to find CITATION.cff file
|
// Try to find CITATION.cff file
|
||||||
const citationCff = (() => {
|
const citationCff = (() => {
|
||||||
@ -33,27 +32,55 @@ export default function cffToJsonPlugin() {
|
|||||||
const citationJson = (() => {
|
const citationJson = (() => {
|
||||||
if (!citationCff) return null;
|
if (!citationCff) return null;
|
||||||
try {
|
try {
|
||||||
return JSON.stringify(
|
return Cite(citationCff).format("data", {
|
||||||
Cite(citationCff).format("data", {
|
format: "object",
|
||||||
format: "object",
|
lang: "en-us",
|
||||||
lang: "en-us",
|
});
|
||||||
}),
|
|
||||||
null,
|
|
||||||
2
|
|
||||||
);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(`Error converting CITATION.cff to JSON: ${error.message}`);
|
console.log(`Error converting CITATION.cff to JSON: ${error.message}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Replace target string with citation JSON
|
// Try to convert CITATION.cff to APA string
|
||||||
if (!citationJson) {
|
const citationApa = (() => {
|
||||||
|
try {
|
||||||
|
return Cite(citationJson).format("data", {
|
||||||
|
format: "html",
|
||||||
|
template: "citation-apa",
|
||||||
|
lang: "en-us",
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`Error converting CITATION.cff to APA string: ${error.message}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
// Try to convert CITATION.cff to bibtex string
|
||||||
|
const citationBibtex = (() => {
|
||||||
|
if (!citationJson) return null;
|
||||||
|
try {
|
||||||
|
let bibtexCitation = Cite(citationJson).format("data", {
|
||||||
|
format: "html",
|
||||||
|
template: "citation-bibtex",
|
||||||
|
lang: "en-us",
|
||||||
|
});
|
||||||
|
return bibtexCitation;
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`Error converting CITATION.cff to bibtex string: ${error.message}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
// Replace target string with citation APA and bibtex strings
|
||||||
|
if (!citationApa && !citationBibtex) {
|
||||||
return { code: code };
|
return { code: code };
|
||||||
}
|
}
|
||||||
const citationString = "citation: " + citationJson;
|
const citationString = `citation: { "apa": "${citationApa}", "bibtex": "${citationBibtex}" }`;
|
||||||
|
const targetString = "citation: []";
|
||||||
const startIndex = code.indexOf(targetString);
|
const startIndex = code.indexOf(targetString);
|
||||||
if (startIndex !== -1) {
|
if (startIndex !== -1) {
|
||||||
|
console.log(citationApa);
|
||||||
magicString.overwrite(startIndex, startIndex + targetString.length, citationString);
|
magicString.overwrite(startIndex, startIndex + targetString.length, citationString);
|
||||||
return { code: magicString.toString() };
|
return { code: magicString.toString() };
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Cite } from "@citation-js/core";
|
|
||||||
import autoBind from "auto-bind";
|
import autoBind from "auto-bind";
|
||||||
// To work with citations
|
// To work with citations
|
||||||
import { Class } from "type-fest";
|
import { Class } from "type-fest";
|
||||||
@ -267,19 +266,8 @@ export class JsPsych {
|
|||||||
format: "apa" | "bibtex"
|
format: "apa" | "bibtex"
|
||||||
) {
|
) {
|
||||||
plugins.map((plugin) => {
|
plugins.map((plugin) => {
|
||||||
let pluginCite = Cite(plugin["info"].citation);
|
let pluginCitation = plugin["info"].citation;
|
||||||
let apaCitation = pluginCite.format("data", {
|
console.log(format == "apa" ? pluginCitation.apa : pluginCitation.bibtex);
|
||||||
format: "string",
|
|
||||||
template: "citation-apa",
|
|
||||||
lang: "en-us",
|
|
||||||
});
|
|
||||||
let bibtexCitation = pluginCite.format("data", {
|
|
||||||
format: "string",
|
|
||||||
template: "citation-bibtex",
|
|
||||||
lang: "en-us",
|
|
||||||
});
|
|
||||||
console.log(apaCitation);
|
|
||||||
console.log(bibtexCitation);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user