closes #183, export bibliography to RTF
This commit is contained in:
parent
feff0aa531
commit
dac5bbb3f3
|
@ -20,7 +20,8 @@
|
||||||
<groupbox>
|
<groupbox>
|
||||||
<caption label="&bibliography.output.label;"/>
|
<caption label="&bibliography.output.label;"/>
|
||||||
<radiogroup id="output-radio">
|
<radiogroup id="output-radio">
|
||||||
<radio id="save-as-html" selected="true" label="&bibliography.saveAsHTML.label;"/>
|
<radio id="save-as-rtf" selected="true" label="&bibliography.saveAsRTF.label;"/>
|
||||||
|
<radio id="save-as-html" label="&bibliography.saveAsHTML.label;"/>
|
||||||
<radio id="copy-to-clipboard" label="&bibliography.copyToClipboard.label;"/>
|
<radio id="copy-to-clipboard" label="&bibliography.copyToClipboard.label;"/>
|
||||||
<radio id="print" label="&bibliography.print.label;"/>
|
<radio id="print" label="&bibliography.print.label;"/>
|
||||||
</radiogroup>
|
</radiogroup>
|
||||||
|
|
|
@ -198,8 +198,14 @@ Scholar_File_Interface = new function() {
|
||||||
var newDialog = window.openDialog("chrome://scholar/content/bibliography.xul",
|
var newDialog = window.openDialog("chrome://scholar/content/bibliography.xul",
|
||||||
"_blank","chrome,modal,centerscreen", io);
|
"_blank","chrome,modal,centerscreen", io);
|
||||||
|
|
||||||
|
// determine output format
|
||||||
|
var format = "HTML";
|
||||||
|
if(io.output == "save-as-rtf") {
|
||||||
|
format = "RTF";
|
||||||
|
}
|
||||||
|
|
||||||
// generate bibliography
|
// generate bibliography
|
||||||
var bibliography = Scholar.Cite.getBibliography(io.style, items);
|
var bibliography = Scholar.Cite.getBibliography(io.style, items, format);
|
||||||
|
|
||||||
if(io.output == "print") {
|
if(io.output == "print") {
|
||||||
// printable bibliography, using a hidden browser
|
// printable bibliography, using a hidden browser
|
||||||
|
@ -232,19 +238,8 @@ Scholar_File_Interface = new function() {
|
||||||
Scholar.Browser.deleteHiddenBrowser(browser);
|
Scholar.Browser.deleteHiddenBrowser(browser);
|
||||||
bibliographyStream.close();
|
bibliographyStream.close();
|
||||||
} else if(io.output == "save-as-html") {
|
} else if(io.output == "save-as-html") {
|
||||||
// savable bibliography, using a file stream
|
var fStream = _saveBibliography("HTML");
|
||||||
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
if(fStream !== false) {
|
||||||
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
|
||||||
.createInstance(nsIFilePicker);
|
|
||||||
fp.init(window, "Save Bibliography", nsIFilePicker.modeSave);
|
|
||||||
fp.appendFilters(nsIFilePicker.filterHTML);
|
|
||||||
var rv = fp.show();
|
|
||||||
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
|
|
||||||
// open file
|
|
||||||
var fStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
|
|
||||||
createInstance(Components.interfaces.nsIFileOutputStream);
|
|
||||||
fStream.init(fp.file, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate
|
|
||||||
|
|
||||||
var html = "";
|
var html = "";
|
||||||
html +='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n';
|
html +='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n';
|
||||||
html +='<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">\n';
|
html +='<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">\n';
|
||||||
|
@ -257,7 +252,12 @@ Scholar_File_Interface = new function() {
|
||||||
html +='</body>\n';
|
html +='</body>\n';
|
||||||
html +='</html>\n';
|
html +='</html>\n';
|
||||||
fStream.write(html, html.length);
|
fStream.write(html, html.length);
|
||||||
|
fStream.close();
|
||||||
|
}
|
||||||
|
} else if(io.output == "save-as-rtf") {
|
||||||
|
var fStream = _saveBibliography("RTF");
|
||||||
|
if(fStream !== false) {
|
||||||
|
fStream.write(bibliography, bibliography.length);
|
||||||
fStream.close();
|
fStream.close();
|
||||||
}
|
}
|
||||||
} else if(io.output == "copy-to-clipboard") {
|
} else if(io.output == "copy-to-clipboard") {
|
||||||
|
@ -278,6 +278,31 @@ Scholar_File_Interface = new function() {
|
||||||
clipboardService.setData(transferable, null, Components.interfaces.nsIClipboard.kGlobalClipboard);
|
clipboardService.setData(transferable, null, Components.interfaces.nsIClipboard.kGlobalClipboard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _saveBibliography(format) {
|
||||||
|
// savable bibliography, using a file stream
|
||||||
|
const nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||||
|
var fp = Components.classes["@mozilla.org/filepicker;1"]
|
||||||
|
.createInstance(nsIFilePicker);
|
||||||
|
fp.init(window, "Save Bibliography", nsIFilePicker.modeSave);
|
||||||
|
|
||||||
|
if(format == "RTF") {
|
||||||
|
fp.appendFilter("RTF", "*.rtf");
|
||||||
|
} else {
|
||||||
|
fp.appendFilters(nsIFilePicker.filterHTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
var rv = fp.show();
|
||||||
|
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
|
||||||
|
// open file
|
||||||
|
var fStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
|
||||||
|
createInstance(Components.interfaces.nsIFileOutputStream);
|
||||||
|
fStream.init(fp.file, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate
|
||||||
|
return fStream;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handles the display of a progress indicator
|
// Handles the display of a progress indicator
|
||||||
|
|
|
@ -23,7 +23,7 @@ Scholar.Cite = new function() {
|
||||||
return stylesObject;
|
return stylesObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBibliography(cslID, items) {
|
function getBibliography(cslID, items, format) {
|
||||||
// get style
|
// get style
|
||||||
var sql = "SELECT csl FROM csl WHERE cslID = ?";
|
var sql = "SELECT csl FROM csl WHERE cslID = ?";
|
||||||
var style = Scholar.DB.valueQuery(sql, [cslID]);
|
var style = Scholar.DB.valueQuery(sql, [cslID]);
|
||||||
|
@ -37,7 +37,7 @@ Scholar.Cite = new function() {
|
||||||
// create a CSL instance
|
// create a CSL instance
|
||||||
var cslInstance = new CSL(style);
|
var cslInstance = new CSL(style);
|
||||||
// return bibliography
|
// return bibliography
|
||||||
return cslInstance.createBibliography(itemArrays, "HTML");
|
return cslInstance.createBibliography(itemArrays, format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,6 @@ CSL = function(csl) {
|
||||||
}
|
}
|
||||||
// load defaults from CSL
|
// load defaults from CSL
|
||||||
this._parseFieldDefaults(this._csl.defaults);
|
this._parseFieldDefaults(this._csl.defaults);
|
||||||
Scholar.debug(this._defaults);
|
|
||||||
|
|
||||||
// decide whether to parse bibliography, or, if none exists, citation
|
// decide whether to parse bibliography, or, if none exists, citation
|
||||||
if(this._csl.bibliography.length()) {
|
if(this._csl.bibliography.length()) {
|
||||||
|
@ -106,8 +105,6 @@ CSL = function(csl) {
|
||||||
this._serializations[0] = new Object();
|
this._serializations[0] = new Object();
|
||||||
this._types[0] = this._parseFields(this._itemElement.children(), 0);
|
this._types[0] = this._parseFields(this._itemElement.children(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Scholar.debug(this._types);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -131,6 +128,19 @@ CSL.prototype.createBibliography = function(items, format) {
|
||||||
|
|
||||||
// process items
|
// process items
|
||||||
var output = "";
|
var output = "";
|
||||||
|
|
||||||
|
if(format == "HTML") {
|
||||||
|
var style = "";
|
||||||
|
if(this._opt.hangingIndent) {
|
||||||
|
style = "margin-left:0.5in;text-indent:-0.5in;";
|
||||||
|
}
|
||||||
|
} else if(format == "RTF") {
|
||||||
|
output += "{\\rtf\\mac\\ansicpg10000{\\fonttbl\\f0\\froman Times New Roman;}{\\colortbl;\\red255\\green255\\blue255;}\\pard\\f0";
|
||||||
|
if(this._opt.hangingIndent) {
|
||||||
|
output += "\\li720\\fi-720";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for(var i in items) {
|
for(var i in items) {
|
||||||
var item = items[i];
|
var item = items[i];
|
||||||
if(item.itemType == "note" || item.itemType == "file") {
|
if(item.itemType == "note" || item.itemType == "file") {
|
||||||
|
@ -186,16 +196,28 @@ CSL.prototype.createBibliography = function(items, format) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(format == "HTML") {
|
|
||||||
output += '<p style="margin-left:0.5in;text-indent:-0.5in">';
|
|
||||||
|
|
||||||
if(this._class == "note") {
|
if(this._class == "note") {
|
||||||
// add superscript number for footnotes
|
// add superscript number for footnotes
|
||||||
output += (parseInt(i)+1).toString()+". ";
|
string += (parseInt(i)+1).toString()+". ";
|
||||||
}
|
}
|
||||||
|
|
||||||
output += string+'</p>';
|
// add line feeds
|
||||||
|
if(format == "HTML") {
|
||||||
|
output += "<p";
|
||||||
|
|
||||||
|
if(style) {
|
||||||
|
output += ' style="'+style+'"';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output += ">"+string+"</p>";
|
||||||
|
} else if(format == "RTF") {
|
||||||
|
output += string+"\\\r\n\\\r\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(format == "RTF") {
|
||||||
|
// drop last 6 characters of output (last two returns)
|
||||||
|
output = output.substr(0, output.length-6)+"}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
|
@ -687,7 +709,6 @@ CSL.prototype._processDate = function(string) {
|
||||||
* formats a string according to the cs-format attributes on element
|
* formats a string according to the cs-format attributes on element
|
||||||
*/
|
*/
|
||||||
CSL.prototype._formatString = function(element, string, format) {
|
CSL.prototype._formatString = function(element, string, format) {
|
||||||
if(element["text-transform"]) {
|
|
||||||
if(element["text-transform"] == "lowercase") {
|
if(element["text-transform"] == "lowercase") {
|
||||||
// all lowercase
|
// all lowercase
|
||||||
string = string.toLowerCase();
|
string = string.toLowerCase();
|
||||||
|
@ -698,7 +719,6 @@ CSL.prototype._formatString = function(element, string, format) {
|
||||||
// capitalize first
|
// capitalize first
|
||||||
string = string[0].toUpperCase()+string.substr(1);
|
string = string[0].toUpperCase()+string.substr(1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(format == "HTML") {
|
if(format == "HTML") {
|
||||||
var style = "";
|
var style = "";
|
||||||
|
@ -714,6 +734,16 @@ CSL.prototype._formatString = function(element, string, format) {
|
||||||
if(style) {
|
if(style) {
|
||||||
string = '<span style="'+style+'">'+string+'</span>';
|
string = '<span style="'+style+'">'+string+'</span>';
|
||||||
}
|
}
|
||||||
|
} else if(format == "RTF") {
|
||||||
|
if(element["font-style"] == "oblique" || element["font-style"] == "italic") {
|
||||||
|
string = "\\i "+string+"\\i0 ";
|
||||||
|
}
|
||||||
|
if(element["font-variant"] == "small-caps") {
|
||||||
|
string = "\\scaps "+string+"\\scaps0 ";
|
||||||
|
}
|
||||||
|
if(element["font-weight"] == "bold") {
|
||||||
|
string = "\\b "+string+"\\b0 ";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(format != "compare" && element.prefix) {
|
if(format != "compare" && element.prefix) {
|
||||||
|
|
|
@ -48,7 +48,8 @@
|
||||||
|
|
||||||
<!ENTITY bibliography.title "Create Bibliography">
|
<!ENTITY bibliography.title "Create Bibliography">
|
||||||
<!ENTITY bibliography.style.label "Citation Style:">
|
<!ENTITY bibliography.style.label "Citation Style:">
|
||||||
<!ENTITY bibliography.output.label "Output Format:">
|
<!ENTITY bibliography.output.label "Output Format">
|
||||||
|
<!ENTITY bibliography.saveAsRTF.label "Save as RTF">
|
||||||
<!ENTITY bibliography.saveAsHTML.label "Save as HTML">
|
<!ENTITY bibliography.saveAsHTML.label "Save as HTML">
|
||||||
<!ENTITY bibliography.copyToClipboard.label "Copy to Clipboard">
|
<!ENTITY bibliography.copyToClipboard.label "Copy to Clipboard">
|
||||||
<!ENTITY bibliography.print.label "Print">
|
<!ENTITY bibliography.print.label "Print">
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
-- 47
|
-- 48
|
||||||
|
|
||||||
-- Set the following timestamp to the most recent scraper update date
|
-- Set the following timestamp to the most recent scraper update date
|
||||||
REPLACE INTO "version" VALUES ('repository', STRFTIME('%s', '2006-08-11 11:18:00'));
|
REPLACE INTO "version" VALUES ('repository', STRFTIME('%s', '2006-08-11 11:18:00'));
|
||||||
|
@ -4990,7 +4990,7 @@ REPLACE INTO "csl" VALUES('http://purl.org/net/xbiblio/csl/styles/apa.csl', '200
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
<group class="container" prefix=" " suffix=".">
|
<group class="container" prefix=" " suffix=".">
|
||||||
<titles relation="container" font-style="italic" prefix=" "/>
|
<titles relation="container" font-style="italic"/>
|
||||||
<volume prefix=", " font-style="italic"/>
|
<volume prefix=", " font-style="italic"/>
|
||||||
<issue prefix="(" suffix=")"/>
|
<issue prefix="(" suffix=")"/>
|
||||||
<pages prefix=", "/>
|
<pages prefix=", "/>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user