closes #183, export bibliography to RTF
This commit is contained in:
parent
feff0aa531
commit
dac5bbb3f3
|
@ -20,7 +20,8 @@
|
|||
<groupbox>
|
||||
<caption label="&bibliography.output.label;"/>
|
||||
<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="print" label="&bibliography.print.label;"/>
|
||||
</radiogroup>
|
||||
|
|
|
@ -198,8 +198,14 @@ Scholar_File_Interface = new function() {
|
|||
var newDialog = window.openDialog("chrome://scholar/content/bibliography.xul",
|
||||
"_blank","chrome,modal,centerscreen", io);
|
||||
|
||||
// determine output format
|
||||
var format = "HTML";
|
||||
if(io.output == "save-as-rtf") {
|
||||
format = "RTF";
|
||||
}
|
||||
|
||||
// generate bibliography
|
||||
var bibliography = Scholar.Cite.getBibliography(io.style, items);
|
||||
var bibliography = Scholar.Cite.getBibliography(io.style, items, format);
|
||||
|
||||
if(io.output == "print") {
|
||||
// printable bibliography, using a hidden browser
|
||||
|
@ -232,19 +238,8 @@ Scholar_File_Interface = new function() {
|
|||
Scholar.Browser.deleteHiddenBrowser(browser);
|
||||
bibliographyStream.close();
|
||||
} else if(io.output == "save-as-html") {
|
||||
// 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);
|
||||
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 fStream = _saveBibliography("HTML");
|
||||
if(fStream !== false) {
|
||||
var html = "";
|
||||
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';
|
||||
|
@ -257,7 +252,12 @@ Scholar_File_Interface = new function() {
|
|||
html +='</body>\n';
|
||||
html +='</html>\n';
|
||||
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();
|
||||
}
|
||||
} else if(io.output == "copy-to-clipboard") {
|
||||
|
@ -278,6 +278,31 @@ Scholar_File_Interface = new function() {
|
|||
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
|
||||
|
|
|
@ -23,7 +23,7 @@ Scholar.Cite = new function() {
|
|||
return stylesObject;
|
||||
}
|
||||
|
||||
function getBibliography(cslID, items) {
|
||||
function getBibliography(cslID, items, format) {
|
||||
// get style
|
||||
var sql = "SELECT csl FROM csl WHERE cslID = ?";
|
||||
var style = Scholar.DB.valueQuery(sql, [cslID]);
|
||||
|
@ -37,7 +37,7 @@ Scholar.Cite = new function() {
|
|||
// create a CSL instance
|
||||
var cslInstance = new CSL(style);
|
||||
// return bibliography
|
||||
return cslInstance.createBibliography(itemArrays, "HTML");
|
||||
return cslInstance.createBibliography(itemArrays, format);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,6 @@ CSL = function(csl) {
|
|||
}
|
||||
// load defaults from CSL
|
||||
this._parseFieldDefaults(this._csl.defaults);
|
||||
Scholar.debug(this._defaults);
|
||||
|
||||
// decide whether to parse bibliography, or, if none exists, citation
|
||||
if(this._csl.bibliography.length()) {
|
||||
|
@ -106,8 +105,6 @@ CSL = function(csl) {
|
|||
this._serializations[0] = new Object();
|
||||
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
|
||||
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) {
|
||||
var item = items[i];
|
||||
if(item.itemType == "note" || item.itemType == "file") {
|
||||
|
@ -185,19 +195,31 @@ CSL.prototype.createBibliography = function(items, format) {
|
|||
string = string + this._opt.format.suffix;
|
||||
}
|
||||
}
|
||||
|
||||
if(format == "HTML") {
|
||||
output += '<p style="margin-left:0.5in;text-indent:-0.5in">';
|
||||
|
||||
if(this._class == "note") {
|
||||
// add superscript number for footnotes
|
||||
output += (parseInt(i)+1).toString()+". ";
|
||||
if(this._class == "note") {
|
||||
// add superscript number for footnotes
|
||||
string += (parseInt(i)+1).toString()+". ";
|
||||
}
|
||||
|
||||
// add line feeds
|
||||
if(format == "HTML") {
|
||||
output += "<p";
|
||||
|
||||
if(style) {
|
||||
output += ' style="'+style+'"';
|
||||
}
|
||||
|
||||
output += string+'</p>';
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -687,17 +709,15 @@ CSL.prototype._processDate = function(string) {
|
|||
* formats a string according to the cs-format attributes on element
|
||||
*/
|
||||
CSL.prototype._formatString = function(element, string, format) {
|
||||
if(element["text-transform"]) {
|
||||
if(element["text-transform"] == "lowercase") {
|
||||
// all lowercase
|
||||
string = string.toLowerCase();
|
||||
} else if(element["text-transform"] == "uppercase") {
|
||||
// all uppercase
|
||||
string = string.toUpperCase();
|
||||
} else if(element["text-transform"] == "capitalize") {
|
||||
// capitalize first
|
||||
string = string[0].toUpperCase()+string.substr(1);
|
||||
}
|
||||
if(element["text-transform"] == "lowercase") {
|
||||
// all lowercase
|
||||
string = string.toLowerCase();
|
||||
} else if(element["text-transform"] == "uppercase") {
|
||||
// all uppercase
|
||||
string = string.toUpperCase();
|
||||
} else if(element["text-transform"] == "capitalize") {
|
||||
// capitalize first
|
||||
string = string[0].toUpperCase()+string.substr(1);
|
||||
}
|
||||
|
||||
if(format == "HTML") {
|
||||
|
@ -714,6 +734,16 @@ CSL.prototype._formatString = function(element, string, format) {
|
|||
if(style) {
|
||||
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) {
|
||||
|
|
|
@ -48,7 +48,8 @@
|
|||
|
||||
<!ENTITY bibliography.title "Create Bibliography">
|
||||
<!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.copyToClipboard.label "Copy to Clipboard">
|
||||
<!ENTITY bibliography.print.label "Print">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
-- 47
|
||||
-- 48
|
||||
|
||||
-- Set the following timestamp to the most recent scraper update date
|
||||
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 class="container" prefix=" " suffix=".">
|
||||
<titles relation="container" font-style="italic" prefix=" "/>
|
||||
<titles relation="container" font-style="italic"/>
|
||||
<volume prefix=", " font-style="italic"/>
|
||||
<issue prefix="(" suffix=")"/>
|
||||
<pages prefix=", "/>
|
||||
|
|
Loading…
Reference in New Issue
Block a user