adds short roles to CSL (Ed. instead of Editor)

adds COinS to exported HTML
uses real lists in HTML output
fixes other small citation style issues
This commit is contained in:
Simon Kornblith 2006-08-19 23:14:27 +00:00
parent 89acdf101c
commit 94bd2415da
4 changed files with 228 additions and 235 deletions

View file

@ -53,7 +53,7 @@ CSL = function(csl) {
this._init(); this._init();
// load localizations // load localizations
this._terms = this._parseTerms(this._csl.terms); this._terms = this._parseLocales(this._csl.terms);
// load class defaults // load class defaults
this._class = this._csl["@class"].toString(); this._class = this._csl["@class"].toString();
@ -130,15 +130,18 @@ CSL.prototype.createBibliography = function(items, format) {
var output = ""; var output = "";
if(format == "HTML") { if(format == "HTML") {
var style = ""; if(this._class == "note") {
if(this._opt.hangingIndent) { output += '<ol>\r\n';
style = "margin-left:0.5in;text-indent:-0.5in;"; } else if(this._opt.hangingIndent) {
output += '<div style="margin-left:0.5in;text-indent:-0.5in;">\r\n';
} }
} else if(format == "RTF") { } else if(format == "RTF") {
var index = 0;
output += "{\\rtf\\ansi{\\fonttbl\\f0\\froman Times New Roman;}{\\colortbl;\\red255\\green255\\blue255;}\\pard\\f0"; output += "{\\rtf\\ansi{\\fonttbl\\f0\\froman Times New Roman;}{\\colortbl;\\red255\\green255\\blue255;}\\pard\\f0";
if(this._opt.hangingIndent) { if(this._opt.hangingIndent) {
output += "\\li720\\fi-720"; output += "\\li720\\fi-720";
} }
output += "\r\n";
} }
for(var i in items) { for(var i in items) {
@ -196,26 +199,32 @@ CSL.prototype.createBibliography = function(items, format) {
} }
} }
if(this._class == "note") {
// add superscript number for footnotes
string += (parseInt(i)+1).toString()+". ";
}
// add line feeds // add line feeds
if(format == "HTML") { if(format == "HTML") {
output += "<p"; var coins = Scholar.OpenURL.createContextObject(item, "1.0");
string += '<span class="Z3988" title="'+coins+'"></span>';
if(style) { if(this._class == "note") {
output += ' style="'+style+'"'; output += "<li>"+string+"</li>\r\n";
} else {
output += "<p>"+string+"</p>\r\n";
} }
output += ">"+string+"</p>";
} else if(format == "RTF") { } else if(format == "RTF") {
if(this._class == "note") {
index++;
output += index+". ";
}
output += string+"\\\r\n\\\r\n"; output += string+"\\\r\n\\\r\n";
} }
} }
if(format == "RTF") { if(format == "HTML") {
if(this._class == "note") {
output += '</ol>';
} else if(this._opt.hangingIndent) {
output += '</div>';
}
} else if(format == "RTF") {
// drop last 6 characters of output (last two returns) // drop last 6 characters of output (last two returns)
output = output.substr(0, output.length-6)+"}"; output = output.substr(0, output.length-6)+"}";
} }
@ -304,12 +313,12 @@ CSL.prototype._init = function() {
req.send(null); req.send(null);
// get default terms // get default terms
var terms = new XML(this._cleanXML(req.responseText)); var locales = new XML(this._cleanXML(req.responseText));
CSL._defaultTerms = this._parseTerms(terms); CSL._defaultTerms = this._parseLocales(locales);
} }
} }
CSL.prototype._parseTerms = function(termXML) { CSL.prototype._parseLocales = function(termXML) {
// return defaults if there are no terms // return defaults if there are no terms
if(!termXML.length()) { if(!termXML.length()) {
return (CSL._defaultTerms ? CSL._defaultTerms : {}); return (CSL._defaultTerms ? CSL._defaultTerms : {});
@ -328,21 +337,42 @@ CSL.prototype._parseTerms = function(termXML) {
return (CSL._defaultTerms ? CSL._defaultTerms : {}); return (CSL._defaultTerms ? CSL._defaultTerms : {});
} }
var termArray = new Array(); var termArray = new Object();
termArray["default"] = new Object();
if(CSL._defaultTerms) { if(CSL._defaultTerms) {
// ugh. copy default array. javascript dumb. // ugh. copy default array. javascript dumb.
for(var i in CSL._defaultTerms) { for(var i in CSL._defaultTerms) {
termArray[i] = new Object();
for(var j in CSL._defaulTerms[i]) {
if(typeof(CSL._defaultTerms[i]) == "object") { if(typeof(CSL._defaultTerms[i]) == "object") {
termArray[i] = [CSL._defaultTerms[i][0], termArray[i][j] = [CSL._defaultTerms[i][j][0],
CSL._defaultTerms[i][1]]; CSL._defaultTerms[i][j][1]];
} else { } else {
termArray[i] = CSL._defaultTerms[i]; termArray[i][j] = CSL._defaultTerms[i][j];
}
} }
} }
} }
// loop through terms // loop through terms
for each(var term in locale.term) { this._parseTerms(locale.term, termArray["default"]);
// loop through term sets
locale._termSets = new Object();
for each(var termSet in locale["term-set"]) {
var name = termSet.@name.toString();
if(!termArray[name]) {
termArray[name] = new Object();
}
this._parseTerms(termSet.term, termArray[name]);
}
return termArray;
}
CSL.prototype._parseTerms = function(terms, termArray) {
for each(var term in terms) {
var name = term.@name.toString(); var name = term.@name.toString();
if(!name) { if(!name) {
throw("citations cannot be generated: no name defined on term in CSL"); throw("citations cannot be generated: no name defined on term in CSL");
@ -370,14 +400,12 @@ CSL.prototype._parseTerms = function(termXML) {
termArray[name] = term.text().toString(); termArray[name] = term.text().toString();
} }
} }
return termArray;
} }
/* /*
* parses attributes and children for a CSL field * parses attributes and children for a CSL field
*/ */
CSL.prototype._parseFieldAttrChildren = function(element, desc) { CSL.prototype._parseFieldAttrChildren = function(element, desc, ignoreChildren) {
if(!desc) { if(!desc) {
var desc = new Object(); var desc = new Object();
} }
@ -389,6 +417,7 @@ CSL.prototype._parseFieldAttrChildren = function(element, desc) {
} }
var children = element.children(); var children = element.children();
if(!ignoreChildren) {
if(children.length()) { if(children.length()) {
// parse children // parse children
@ -430,6 +459,7 @@ CSL.prototype._parseFieldAttrChildren = function(element, desc) {
} }
} }
} }
}
return desc; return desc;
} }
@ -456,21 +486,18 @@ CSL.prototype._parseFieldDefaults = function(ref) {
/* /*
* parses a list of fields into an array of objects * parses a list of fields into an array of objects
*/ */
CSL.prototype._parseFields = function(ref, type) { CSL.prototype._parseFields = function(ref, type, noInherit) {
var typeDesc = new Array(); var typeDesc = new Array();
for each(var element in ref) { for each(var element in ref) {
if(element.namespace() == CSL.ns) { // ignore elements in other namespaces if(element.namespace() == CSL.ns) { // ignore elements in other namespaces
var itemDesc = new Object(); var itemDesc = new Object();
itemDesc.name = element.localName(); itemDesc.name = element.localName();
// parse attributes on this field
this._parseFieldAttrChildren(element, itemDesc);
// add defaults, but only if we're parsing as a reference type // add defaults, but only if we're parsing as a reference type
if(type != undefined) { if(type != undefined) {
var fieldDefaults = this._getFieldDefaults(itemDesc.name); var fieldDefaults = this._getFieldDefaults(itemDesc.name);
itemDesc = this._merge(fieldDefaults, itemDesc); itemDesc = this._merge(fieldDefaults, itemDesc);
if(this._opt.inheritFormat) { if(!noInherit) {
itemDesc = this._merge(this._opt.inheritFormat, itemDesc); itemDesc = this._merge(this._opt.inheritFormat, itemDesc);
} }
@ -481,19 +508,17 @@ CSL.prototype._parseFields = function(ref, type) {
} }
// parse group children // parse group children
if(itemDesc.name == "group" && itemDesc.children) { if(itemDesc.name == "group") {
for(var i in itemDesc.children) { // parse attributes on this field, but ignore children
// don't bother merging fieldDefaults this._parseFieldAttrChildren(element, itemDesc, true);
itemDesc.children[i] = this._merge(this._getFieldDefaults(itemDesc.children[i].name),
itemDesc.children[i]); var children = element.children();
if(type != undefined) { if(children.length()) {
// serialize children itemDesc.children = this._parseFields(children, type, true);
itemDesc.children[i]._serialized = this._serializeElement(itemDesc.children[i].name,
itemDesc.children[i]);
// add to serialization for type
this._serializations[type][itemDesc._serialized] = itemDesc;
}
} }
} else {
// parse attributes on this field
this._parseFieldAttrChildren(element, itemDesc);
} }
typeDesc.push(itemDesc); typeDesc.push(itemDesc);
@ -650,21 +675,24 @@ CSL.prototype._getFieldDefaults = function(elementName) {
/* /*
* gets a term, in singular or plural form * gets a term, in singular or plural form
*/ */
CSL.prototype._getTerm = function(term, plural) { CSL.prototype._getTerm = function(term, plural, termSet) {
if(!this._terms[term]) { if(!termSet) {
termSet = "default";
}
if(!this._terms[termSet][term]) {
return ""; return "";
} }
if(typeof(this._terms[term]) == "object") { // singular and plural forms if(typeof(this._terms[termSet][term]) == "object") { // singular and plural forms
// are available // are available
if(plural) { if(plural) {
return this._terms[term][1]; return this._terms[termSet][term][1];
} else { } else {
return this._terms[term][0]; return this._terms[termSet][term][0];
} }
} }
return this._terms[term]; return this._terms[termSet][term];
} }
/* /*
@ -834,7 +862,7 @@ CSL.prototype._formatLocator = function(identifier, element, number, format) {
string = this._getTerm(child["term-name"], plural); string = this._getTerm(child["term-name"], plural);
} else if(identifier && child.name == "label") { } else if(identifier && child.name == "label") {
var plural = (number.indexOf(",") != -1 || number.indexOf("-") != -1); var plural = (number.indexOf(",") != -1 || number.indexOf("-") != -1);
string = this._getTerm(identifier, plural); string = this._getTerm(identifier, plural, child["term-set"]);
} }
if(string) { if(string) {
@ -1128,7 +1156,7 @@ CSL.prototype._processCreators = function(type, element, creators, format) {
} }
string = authorStrings.join(joinString); string = authorStrings.join(joinString);
} else if(child.name == "label") { } else if(child.name == "label") {
string = this._getTerm(type, (maxCreators != 1)); string = this._getTerm(type, (maxCreators != 1), child["term-set"]);
} }

View file

@ -206,8 +206,10 @@ Scholar.OpenURL = new function() {
/* /*
* Generates an OpenURL ContextObject from an item * Generates an OpenURL ContextObject from an item
*/ */
function createContextObject(itemObject, version) { function createContextObject(item, version) {
var item = itemObject.toArray(); if(item.toArray) {
item = itemObject.toArray();
}
var identifiers = new Array(); var identifiers = new Array();
if(item.DOI) { if(item.DOI) {
@ -308,22 +310,36 @@ Scholar.OpenURL = new function() {
* accepts an item array to fill, or creates and returns a new item array * accepts an item array to fill, or creates and returns a new item array
*/ */
function parseContextObject(co, item) { function parseContextObject(co, item) {
var coParts = co.split("&");
if(!item) { if(!item) {
var item = new Array(); var item = new Array();
item.creators = new Array(); item.creators = new Array();
} }
var coParts = co.split("&");
// get type // get type
item.itemType = _determineResourceType(coParts); for each(var part in coParts) {
if(part.substr(0, 12) == "rft_val_fmt=") {
var format = unescape(part.substr(12));
if(format == "info:ofi/fmt:kev:mtx:journal") {
item.itemType = "journalArticle";
} else if(format == "info:ofi/fmt:kev:mtx:book") {
if(Scholar.inArray("rft.genre=bookitem", coParts)) {
item.itemType = "bookSection";
} else {
item.itemType = "book";
}
break;
}
}
}
if(!item.itemType) { if(!item.itemType) {
return false; return false;
} }
var pagesKey = ""; var pagesKey = "";
for each(part in coParts) { for each(var part in coParts) {
var keyVal = part.split("="); var keyVal = part.split("=");
var key = keyVal[0]; var key = keyVal[0];
var value = unescape(keyVal[1].replace(/\+|%2[bB]/g, " ")); var value = unescape(keyVal[1].replace(/\+|%2[bB]/g, " "));
@ -419,30 +435,6 @@ Scholar.OpenURL = new function() {
return item; return item;
} }
/*
* Determines the type of an OpenURL contextObject
*/
function _determineResourceType(coParts) {
// determine resource type
var type = false;
for(var i in coParts) {
if(coParts[i].substr(0, 12) == "rft_val_fmt=") {
var format = unescape(coParts[i].substr(12));
if(format == "info:ofi/fmt:kev:mtx:journal") {
var type = "journal";
} else if(format == "info:ofi/fmt:kev:mtx:book") {
if(Scholar.inArray("rft.genre=bookitem", coParts)) {
var type = "bookSection";
} else {
var type = "book";
}
break;
}
}
}
return type;
}
/* /*
* Used to map tags for generating OpenURL contextObjects * Used to map tags for generating OpenURL contextObjects
*/ */

View file

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<terms> <terms>
<locale xml:lang="en"> <locale xml:lang="en">
<term name="in">in</term> <term name="in">in</term>
@ -6,30 +7,51 @@
<term name="forthcoming">forthcoming</term> <term name="forthcoming">forthcoming</term>
<term name="references">References</term> <term name="references">References</term>
<term name="and">and</term> <term name="and">and</term>
<term-set name="locators">
<term name="page"> <term name="page">
<single>page</single> <single>page</single>
<multiple>pages</multiple> <multiple>pages</multiple>
</term> </term>
<term name="page-short"> <term name="paragraph">
<single>paragraph</single>
<multiple>paragraph</multiple>
</term>
</term-set>
<term-set name="locators-short">
<term name="page">
<single>p</single> <single>p</single>
<multiple>pp</multiple> <multiple>pp</multiple>
</term> </term>
<term name="paragraph">
<single></single>
<multiple>¶¶</multiple>
</term>
</term-set>
<term-set name="roles">
<term name="editor"> <term name="editor">
<single>editor</single> <single>editor</single>
<multiple>editors</multiple> <multiple>editors</multiple>
</term> </term>
<term name="editor-short">
<single>ed</single>
<multiple>eds</multiple>
</term>
<term name="translator"> <term name="translator">
<single>translator</single> <single>translator</single>
<multiple>translators</multiple> <multiple>translators</multiple>
</term> </term>
<term name="translator-short"> </term-set>
<term-set name="roles-short">
<term name="editor">
<single>ed</single>
<multiple>eds</multiple>
</term>
<term name="translator">
<single>tran</single> <single>tran</single>
<multiple>trans</multiple> <multiple>trans</multiple>
</term> </term>
</term-set>
<term-set name="roles-verb">
<term name="editor">edited by</term>
<term name="translator">translated by</term>
</term-set>
<term-set name="months">
<term name="month-01">January</term> <term name="month-01">January</term>
<term name="month-02">February</term> <term name="month-02">February</term>
<term name="month-03">March</term> <term name="month-03">March</term>
@ -42,73 +64,20 @@
<term name="month-10">October</term> <term name="month-10">October</term>
<term name="month-11">November</term> <term name="month-11">November</term>
<term name="month-12">December</term> <term name="month-12">December</term>
<term name="month-01-short">Jan</term> </term-set>
<term name="month-02-short">Feb</term> <term-set name="months-short">
<term name="month-03-short">Mar</term> <term name="month-01">Jan</term>
<term name="month-04-short">Apr</term> <term name="month-02">Feb</term>
<term name="month-05-short">May</term> <term name="month-03">Mar</term>
<term name="month-06-short">Jun</term> <term name="month-04">Apr</term>
<term name="month-07-short">Jul</term> <term name="month-05">May</term>
<term name="month-08-short">Aug</term> <term name="month-06">Jun</term>
<term name="month-09-short">Sep</term> <term name="month-07">Jul</term>
<term name="month-10-short">Oct</term> <term name="month-08">Aug</term>
<term name="month-11-short">Nov</term> <term name="month-09">Sep</term>
<term name="month-12-short">Dec</term> <term name="month-10">Oct</term>
</locale> <term name="month-11">Nov</term>
<locale xml:lang="nl"> <term name="month-12">Dec</term>
<term name="in">in</term> </term-set>
<term name="ibid">ibid</term>
<term name="accessed">benaderd</term>
<term name="forthcoming">in voorbereiding</term>
<term name="references">Referenties</term>
<term name="and">en</term>
<term name="page">
<single>pagina</single>
<multiple>pagina's</multiple>
</term>
<term name="page-short">
<single>p</single>
<multiple>pp</multiple>
</term>
<term name="editor">
<single>redacteur</single>
<multiple>redacteurs</multiple>
</term>
<term name="editor-short">
<single>red</single>
<multiple>reds</multiple>
</term>
<term name="translator">
<single>vertaler</single>
<multiple>vertalers</multiple>
</term>
<term name="translator-short">
<single>vert</single>
<multiple>verts</multiple>
</term>
<term name="month-01">januari</term>
<term name="month-02">februari</term>
<term name="month-03">maart</term>
<term name="month-04">april</term>
<term name="month-05">mei</term>
<term name="month-06">juni</term>
<term name="month-07">juli</term>
<term name="month-08">augustus</term>
<term name="month-09">september</term>
<term name="month-10">oktober</term>
<term name="month-11">november</term>
<term name="month-12">december</term>
<term name="month-01-short">jan</term>
<term name="month-02-short">feb</term>
<term name="month-03-short">maa</term>
<term name="month-04-short">apr</term>
<term name="month-05-short">mei</term>
<term name="month-06-short">jun</term>
<term name="month-07-short">jul</term>
<term name="month-08-short">aug</term>
<term name="month-09-short">sep</term>
<term name="month-10-short">okt</term>
<term name="month-11-short">nov</term>
<term name="month-12-short">dec</term>
</locale> </locale>
</terms> </terms>

View file

@ -5360,20 +5360,20 @@ REPLACE INTO "csl" VALUES('http://purl.org/net/xbiblio/csl/styles/apa.csl', '200
<name>Bruce DArcus</name> <name>Bruce DArcus</name>
<email>bdarcus@sourceforge.net</email> <email>bdarcus@sourceforge.net</email>
</author> </author>
<author> <contributor>
<name>Simon Kornblith</name> <name>Simon Kornblith</name>
<email>simon@simonster.com</email> <email>simon@simonster.com</email>
</author> </contributor>
<updated>2006-08-13T23:28:00-05:00</updated> <updated>2006-08-19T17:12:00-05:00</updated>
</info> </info>
<defaults> <defaults>
<contributors name-as-sort-order="no"> <contributor name-as-sort-order="no">
<name and="symbol" initialize-with="."/> <name and="symbol" initialize-with="."/>
<label prefix=", " text-transform="capitalize"/> <label term-set="roles-short" prefix=", " text-transform="capitalize" suffix="."/>
</contributors> </contributor>
<author name-as-sort-order="all"> <author name-as-sort-order="all">
<name and="symbol" sort-separator=", " initialize-with="."/> <name and="symbol" sort-separator=", " initialize-with="."/>
<label prefix=" (" suffix=")" text-transform="capitalize"/> <label term-set="roles-short" prefix=" (" suffix=".)" text-transform="capitalize"/>
<substitute> <substitute>
<choose> <choose>
<editor/> <editor/>
@ -5461,17 +5461,17 @@ REPLACE INTO "csl" VALUES('http://purl.org/net/xbiblio/csl/styles/apa.csl', '200
<text term-name="in" text-transform="capitalize"/> <text term-name="in" text-transform="capitalize"/>
<editor prefix=" " suffix=","> <editor prefix=" " suffix=",">
<name and="symbol" sort-separator=", " initialize-with="."/> <name and="symbol" sort-separator=", " initialize-with="."/>
<label prefix=" (" suffix=")" text-transform="capitalize"/> <label term-set="roles-short" prefix=" (" suffix=")" text-transform="capitalize"/>
</editor> </editor>
<translator prefix=" " suffix=","> <translator prefix=" " suffix=",">
<name and="symbol" sort-separator=", " initialize-with="."/> <name and="symbol" sort-separator=", " initialize-with="."/>
<label prefix=" (" suffix=")" text-transform="capitalize"/> <label term-set="roles-short" prefix=" (" suffix=")" text-transform="capitalize"/>
</translator> </translator>
<titles relation="container" font-style="italic" prefix=" " suffix="."/> <titles relation="container" font-style="italic" prefix=" " suffix="."/>
<titles relation="collection" prefix=" " suffix="."/> <titles relation="collection" prefix=" " suffix="."/>
<publisher prefix=" "/> <publisher prefix=" "/>
<pages prefix=" (" suffix=")"> <pages prefix=" (" suffix=")">
<label text-transform="capitalize" suffix=". "/> <label term-set="locators-short" text-transform="capitalize" suffix=". "/>
<number/> <number/>
</pages> </pages>
</group> </group>
@ -5514,17 +5514,21 @@ REPLACE INTO "csl" VALUES('http://purl.org/net/xbiblio/csl/styles/chicago-note.c
<name>Bruce DArcus</name> <name>Bruce DArcus</name>
<email>bdarcus@sourceforge.net</email> <email>bdarcus@sourceforge.net</email>
</author> </author>
<updated>2006-08-03T04:35:20-07:00</updated> <contributor>
<name>Simon Kornblith</name>
<email>simon@simonster.com</email>
</contributor>
<updated>2006-08-19T17:12:00-05:00</updated>
<summary>The note-without-bibliography variant of the Chicago style.</summary> <summary>The note-without-bibliography variant of the Chicago style.</summary>
</info> </info>
<defaults> <defaults>
<contributor> <contributor>
<label suffix=". " text-transform="lowercase"/> <label term-set="roles-short" suffix=". " text-transform="lowercase"/>
<name and="text"/> <name and="text"/>
</contributor> </contributor>
<author> <author>
<name and="text"/> <name and="text"/>
<label prefix = ", " suffix="." text-transform="lowercase"/> <label term-set="roles-short" prefix=", " suffix="." text-transform="lowercase"/>
<substitute> <substitute>
<choose> <choose>
<editor/> <editor/>