Skip to content

Instantly share code, notes, and snippets.

@hetsch
Created August 1, 2015 07:54
Show Gist options
  • Save hetsch/43b4b51f792271290b89 to your computer and use it in GitHub Desktop.
Save hetsch/43b4b51f792271290b89 to your computer and use it in GitHub Desktop.
Using "author-only" in citeproc
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title></title>
<link rel="stylesheet" type="text/css" media="screen" href="css/master.css" />
<script type="text/javascript" src="jquery.min.js"></script>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<script type="text/javascript" src="citeproc/xmldom.js"></script>
<script type="text/javascript" src="citeproc/citeproc.js"></script>
<script>
$(function() {
var data = [{
"id": 573,
"type": "article-journal",
"title": "There Is Always Time for Rational Skepticism: Reply to Hall et al",
"container-title": "Tourism Management",
"page": "348-351",
"volume": "47",
"source": "CrossRef",
"URL": "http://linkinghub.elsevier.com/retrieve/pii/S0261517714001836",
"DOI": "10.1016/j.tourman.2014.09.013",
"ISSN": "02615177",
"shortTitle": "There Is Always Time for Rational Skepticism",
"language": "en",
"author": [
{
"family": "Shani",
"given": "Amir"
},
{
"family": "Arad",
"given": "Boaz"
}
],
"issued": {
"date-parts": [
[
"2015",
4
]
]
},
"accessed": {
"date-parts": [
[
"2015",
4,
14
]
]
}
},{
"id": 877,
"type": "article-journal",
"title": "Scale, Change and Resilience in Community Tourism Planning",
"container-title": "Tourism Geographies",
"page": "14-22",
"volume": "16",
"issue": "1",
"source": "CrossRef",
"URL": "http://www.tandfonline.com/doi/abs/10.1080/14616688.2013.864325",
"DOI": "10.1080/14616688.2013.864325",
"ISSN": "1461-6688, 1470-1340",
"language": "en",
"author": [
{
"family": "Lew",
"given": "Alan A."
}
],
"issued": {
"date-parts": [
[
"2014",
1
]
]
},
"accessed": {
"date-parts": [
[
"2015",
3,
9
]
]
}
}];
var jqxhr1 = $.ajax('locales-en-US.xml');
var jqxhr2 = $.ajax('apa.csl');
$.when(jqxhr1, jqxhr2).done(function(r1, r2) {
var locale = r1[2].responseText;
var style = r2[2].responseText;
var sys = {
retrieveLocale: function(lang) {
return locale;
}.bind(this),
retrieveItem: function(id) {
//return this.data[id];
var item = data.filter(function(item) {
if ('id' in item && String(item.id).toLowerCase() === String(id).toLowerCase()) {
return true;
}
return false;
});
return item.pop();
}.bind(this)
};
var processor = new CSL.Engine(sys, style, 'en-US');
processor.setOutputFormat('html');
var cluster = {
'citationItems': [
{
'id': '573',
'label': 'page',
'locator': '20',
'author-only': 1
},{
'id': '877',
'author-only': 1
}
],
'properties': {}
};
var p1 = []; // author
var p2 = []; // (year, page, aso.)
//-----------------------------------------------
// TRY 1
//-----------------------------------------------
console.time('call1');
console.log(processor.processCitationCluster(cluster, [], []));
console.timeEnd('call1');
/*
NOTE:
What I expected to get as return value are all two authors:
[{
bibchange=false,
citation_errors=[0]
}, [
[0, "Lew"],
[x, "Shani &#38; Arad"]
]]
What I got:
[{
bibchange=false,
citation_errors=[0]
}, [
[0, "Lew"]
]]
*/
//-----------------------------------------------
// TRY 2
//-----------------------------------------------
// It seems to be not possible to retrieve multiple authors with "author-only" or "suppress-author", iterate over particular cite items
console.time('call2');
cluster.citationItems.forEach(function(item, idx) {
var item = cluster.citationItems[idx];
item['author-only'] = 1;
p1.push(processor.processCitationCluster({
'citationItems': [
item
],
'properties': {}
}, [], []));
delete item['author-only'];
item['suppress-author'] = 1;
p2.push(processor.processCitationCluster({
'citationItems': [
item
],
'properties': {}
}, [], []));
});
console.timeEnd('call2');
console.log(p1, p2)
/*
NOTE:
What I expected to get as return value are all two authors:
[{
bibchange=false,
citation_errors=[0]
}, [
[x, "Shani &#38; Arad"]
]]
What I got (see how the ', p.' was included in the author name):
[{
bibchange=false,
citation_errors=[0]
}, [
[x, "Shani &#38; Arad, p."]
]]
*/
console.log(processor.makeBibliography());
});
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment