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) {
|
||||
if (!filter(id) || (extname(id) !== ".js" && extname(id) !== ".ts")) return;
|
||||
const magicString = new MagicString(code);
|
||||
const targetString = "citation: []";
|
||||
|
||||
// Try to find CITATION.cff file
|
||||
const citationCff = (() => {
|
||||
@ -33,27 +32,55 @@ export default function cffToJsonPlugin() {
|
||||
const citationJson = (() => {
|
||||
if (!citationCff) return null;
|
||||
try {
|
||||
return JSON.stringify(
|
||||
Cite(citationCff).format("data", {
|
||||
format: "object",
|
||||
lang: "en-us",
|
||||
}),
|
||||
null,
|
||||
2
|
||||
);
|
||||
return Cite(citationCff).format("data", {
|
||||
format: "object",
|
||||
lang: "en-us",
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(`Error converting CITATION.cff to JSON: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
|
||||
// Replace target string with citation JSON
|
||||
if (!citationJson) {
|
||||
// Try to convert CITATION.cff to APA string
|
||||
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 };
|
||||
}
|
||||
const citationString = "citation: " + citationJson;
|
||||
const citationString = `citation: { "apa": "${citationApa}", "bibtex": "${citationBibtex}" }`;
|
||||
const targetString = "citation: []";
|
||||
const startIndex = code.indexOf(targetString);
|
||||
if (startIndex !== -1) {
|
||||
console.log(citationApa);
|
||||
magicString.overwrite(startIndex, startIndex + targetString.length, citationString);
|
||||
return { code: magicString.toString() };
|
||||
} else {
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { Cite } from "@citation-js/core";
|
||||
import autoBind from "auto-bind";
|
||||
// To work with citations
|
||||
import { Class } from "type-fest";
|
||||
@ -267,19 +266,8 @@ export class JsPsych {
|
||||
format: "apa" | "bibtex"
|
||||
) {
|
||||
plugins.map((plugin) => {
|
||||
let pluginCite = Cite(plugin["info"].citation);
|
||||
let apaCitation = pluginCite.format("data", {
|
||||
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);
|
||||
let pluginCitation = plugin["info"].citation;
|
||||
console.log(format == "apa" ? pluginCitation.apa : pluginCitation.bibtex);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user