Skip to content

Instantly share code, notes, and snippets.

@andreasplesch
Last active January 22, 2026 20:06
Show Gist options
  • Select an option

  • Save andreasplesch/e3ef72b47da1a947d61b5512c7e0eb3e to your computer and use it in GitHub Desktop.

Select an option

Save andreasplesch/e3ef72b47da1a947d61b5512c7e0eb3e to your computer and use it in GitHub Desktop.
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Demo: Standalone Bibliography &mdash;citeproc-js 1.4.61 documentation</title>
<script type="text/javascript" src="https://raw.githack.com/Juris-M/citeproc-js/b60b9c4e9e14b0445303d540053d9dd39359c733/citeproc.js"></script>
<script type="text/javascript">
// Library of Cornell Conservation Agriculture
// var chosenLibraryItems = "https://api.zotero.org/groups/459003/items?format=csljson&limit=6&itemType=journalArticle";
// Chicago Manual of Style (Full Note)
var chosenStyleID = "bulletin-of-the-seismological-society-of-america";
//acm-siggraph";//chicago-notes-bibliography";
// Fetch citation data
//var xhr = new XMLHttpRequest();
//xhr.open('GET', chosenLibraryItems, false);
//xhr.send(null);
//var citationData = JSON.parse(xhr.responseText);
var citationJSON = `{ "items": [
{
"id": "http://zotero.org/groups/6194483/items/KFG66666",
"type": "article-journal",
"abstract": "Magnetic anomaly patterns in the northeast Pacific Ocean combined with plate theory indicate that a trench existed offshore from western North America during mid-Tertiary time and that the present episode of strike-slip motion in the San Andreas fault system originated after the cessation of subduction, not earlier than 30 m.y. ago. At present, the American and Pacific plates appear to be moving past one another parallel to the San Andreas fault at a rate of 6 cm/yr. Data concerning the late Cenozoic history of motions between these plates is inconclusive, and so 2 probable models are examined. One assumes a constant motion of 6 cm/yr throughout the late Cenozoic, whereas the other assumes that the 2 plates were fixed with respect to one another until 5 m.y. ago, at which time they broke along the San Andreas fault system and began moving at 6 cm/yr. The second model implies that the San Andreas fault took up all the motion at the boundary between the North American and Pacific plates, while the first model suggests the broader view that much of the late Cenozoic tectonic activity of western North America is related to this boundary deformation. The models make testable predictions for the distribution of igneous rocks and for the total amount and timing of deformation expected. Extrapolation of the model of constant motions to the early Cenozoic suggests an era of slightly compressional strike-slip at the edge of North America. A major change in plate motions in late Mesozoic time is suggested.",
"container-title": "GSA Bulletin",
"DOI": "10.1130/0016-7606(1970)81[3513:IOPTFT]2.0.CO;2",
"ISSN": "0016-7606",
"issue": "12",
"journalAbbreviation": "GSA Bulletin",
"page": "3513-3536",
"source": "Silverchair",
"title": "Implications of Plate Tectonics for the Cenozoic Tectonic Evolution of Western North America",
"URL": "https://doi.org/10.1130/0016-7606(1970)81[3513:IOPTFT]2.0.CO;2",
"volume": "81",
"author": [
{
"family": "Atwater",
"given": "Tanya"
}
],
"accessed": {
"date-parts": [
[
"2025",
9,
17
]
]
},
"issued": {
"date-parts": [
[
"1970",
12,
1
]
]
}
}
] }`;
var citationData = JSON.parse(citationJSON);
// Refactor citation data for keyed access
var citations = {};
var itemIDs = [];
for (var i = 0, ilen = citationData.items.length; i < ilen; i++) {
var item = citationData.items[i];
if (!item.issued)
continue;
if (item.URL)
delete item.URL;
var id = item.id;
citations[id] = item;
itemIDs.push(id);
}
// Initialize a system object
citeprocSys = {
retrieveLocale: function(lang) {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://raw.githubusercontent.com/Juris-M/citeproc-js-docs/master/locales-' + lang + '.xml', false);
xhr.send(null);
return xhr.responseText;
},
retrieveItem: function(id) {
return citations[id];
}
};
// Instantiate processor
function getProcessor(styleID) {
// Get the CSL style as a serialized string of XML
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://raw.githubusercontent.com/citation-style-language/styles/master/' + styleID + '.csl', false);
xhr.send(null);
var styleAsText = xhr.responseText;
var citeproc = new CSL.Engine(citeprocSys,styleAsText);
return citeproc;
}
;
// This runs at document ready, and renders the bibliography
function processorOutput() {
ret = '';
var citeproc = getProcessor(chosenStyleID);
citeproc.updateItems(itemIDs);
var bibResult = citeproc.makeBibliography();
return [
"citeproc version: " + citeproc.processor_version,
...bibResult[1]
].join('\n');
}
function fillElement(elementID) {
var content = document.getElementById(elementID);
content.innerHTML = processorOutput();
}
</script>
</head>
<body onload='init()'>
<h2>input citations </h2>
<pre id='inputJSON'></pre>
<h2>used style </h2>
<div id='usedStyle'></div>
<h2>generated bibliography </h2>
<div id='biblio'></div>
<h2>generated bibliography (raw) </h2>
<pre id='biblio_raw'></pre>
<script>
function init() {
//getById = document.body.querySelector;
document.querySelector('#inputJSON').innerHTML = citationJSON;
document.querySelector('#usedStyle').innerHTML = chosenStyleID;
document.querySelector('#biblio').innerHTML = processorOutput();
document.querySelector('#biblio_raw').innerHTML = processorOutput();
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment