This question is about the JavaScript library [{citation.js}](https://citation.js.org/)
. I need to be able to generate in-text citations in various formats. For example:
AMA
Lorem Ipsum is simply dummy text of the printing and typesetting industry (Loomes et al., 2017; Mantzalas et al, 2022).
APA
Lorem Ipsum is simply dummy text of the printing and typesetting industry 1-2.
Although Cite.format
allows you to specify a template, it doesn’t seem to use it. My sample code shows me specifying different template values and obtaining the same generic result.
I assume that means that it uses code from {citeproc-js}
. Citation-JS has plugins. Is one of them used for formatting the citations via CSL? I can’t find any examples.
There is a tutorial for Outputs, but it contains almost no information.
const Cite = require('citation-js');
// Sample BibTeX string for demonstration
const bibtex = `
@article{Loomes2017,
title = {Loomes Title},
author = {Loomes, Rachel and Hull, Laura and Mandy, William Polmear Locke},
date = {2017-06},
journaltitle = {Journal of the American Academy of Child and Adolescent Psychiatry},
volume = {56},
number = {6},
pages = {466--474},
doi = {10.1016/j.jaac.2017.03.013}
}
@article{Mantzalas2022,
title = {Mantzalas Title},
author = {Mantzalas, Jane and Richdale, Amanda L. and Adikari, Achini and Lowe, Jennifer and Dissanayake, Cheryl},
date = {2022-03},
journaltitle = {Autism in Adulthood},
volume = {4},
number = {1},
pages = {52--65},
doi = {10.1089/aut.2021.0021}
}
`;
// Create the citation-js object
const library = new Cite(bibtex);
let single_citation = "Loomes2017";
let double_citation = "Loomes2017,Mantzalas2022";
let single_inline_apa = library.format('citation', {
entry: single_citation,
format: 'html',
template: "apa",
lang: 'en-US'
});
console.log(`single inline APA: ${single_inline_apa}`);
let double_inline_apa =
double_citation
.split(",")
.map(x => x.trim())
.map(x => library.format('citation', {
entry: x,
format: 'html',
template: "apa",
lang: 'en-US'
})
)
.join(",")
console.log(`double inline APA: ${double_inline_apa}`);
let single_inline_ama = library.format('citation', {
entry: single_citation,
format: 'html',
template: "apa",
lang: 'en-US'
});
console.log(`single inline AMA: ${single_inline_ama}`);
let double_inline_ama =
double_citation
.split(",")
.map(x => x.trim())
.map(x => library.format('citation', {
entry: x,
format: 'html',
template: "ama",
lang: 'en-US'
})
)
.join(",")
console.log(`double inline AMA: ${double_inline_ama}`);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Citation-JS Example</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/citation-js/0.7.14/citation.js"></script>
</head>
<body>
<div id="content"></div>
</body>
</html>