- closes #1512, RTF Scan: Page Numbers

- closes #1513, RTF Scan: {Bib} Placemarker Flexibility
- switches citations from parentheses to brackets, to make it easier to distingush between what was reformatted and what wasn't
- adds a list of example citations to RTF scan dialog
This commit is contained in:
Simon Kornblith 2009-06-23 19:49:56 +00:00
parent 6126ceb323
commit 7b58475df7
4 changed files with 51 additions and 12 deletions

View file

@ -96,7 +96,16 @@ var Zotero_RTFScan = new function() {
.createInstance(nsIFilePicker);
fp.init(window, Zotero.getString("rtfScan.saveTitle"), nsIFilePicker.modeSave);
fp.appendFilter(Zotero.getString("rtfScan.rtf"), "*.rtf");
if(inputFile) {
var leafName = inputFile.leafName;
var dotIndex = leafName.lastIndexOf(".");
if(dotIndex != -1) {
leafName = leafName.substr(0, dotIndex);
}
fp.defaultString = leafName+" "+Zotero.getString("rtfScan.scannedFileSuffix")+".rtf";
} else {
fp.defaultString = "Untitled.rtf";
}
var rv = fp.show();
if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
@ -150,7 +159,7 @@ var Zotero_RTFScan = new function() {
const creatorRe = '((?:(?:'+nameRe+', )*'+nameRe+'(?:,? and|,? \\&|,) )?'+nameRe+')(,? et al\\.?)?';
// TODO: localize "and" term
const creatorSplitRe = /(?:,| *(?:and|\&)) +/g;
var citationRe = new RegExp('(\\(|; )('+creatorRe+', (?:"([^"]+)(?:,"|",) )?([0-9]{4})[a-z]?)(?:, ([0-9]+))?(?=[);])|(([A-Z][^ .,;]+)(,? et al\\.?)? (\\(([0-9]{4})[a-z]?\\)))', "gm");
var citationRe = new RegExp('(\\\\\\{|; )('+creatorRe+',? (?:"([^"]+)(?:,"|",) )?([0-9]{4})[a-z]?)(?:,(?: pp?\.?)? ([^ )]+))?(?=;|\\\\\\})|(([A-Z][^ .,;]+)(,? et al\\.?)? (\\\\\\{([0-9]{4})[a-z]?\\\\\\}))', "gm");
// read through RTF file and display items as they're found
// we could read the file in chunks, but unless people start having memory issues, it's
@ -168,7 +177,7 @@ var Zotero_RTFScan = new function() {
var date = m[6];
var pages = m[7];
var start = citationRe.lastIndex-m[0].length;
var end = citationRe.lastIndex+1;
var end = citationRe.lastIndex+2;
} else { // suppressed
var citationString = m[8];
var creators = m[9];
@ -179,6 +188,7 @@ var Zotero_RTFScan = new function() {
var start = citationRe.lastIndex-m[11].length;
var end = citationRe.lastIndex;
}
citationString = citationString.replace("\\{", "{", "g").replace("\\}", "}", "g");
var suppressAuthor = !m[2];
if(lastCitation && lastCitation.end >= start) {
@ -564,15 +574,32 @@ var Zotero_RTFScan = new function() {
// add bibliography
if(style.hasBibliography) {
var bibliography = false;
contents = contents.replace(BIBLIOGRAPHY_PLACEHOLDER, function() {
if(bibliography !== false) {
return bibliography;
} else {
bibliography = style.formatBibliography(itemSet, "RTF");
return bibliography;
var bibliography = style.formatBibliography(itemSet, "RTF");
// cut off initial font formatting
bibliography = bibliography.substr(bibliography.indexOf("\r\n"));
// fix line breaks
var linebreak = "\r\n";
if(contents.indexOf("\r\n") == -1) {
bibliography = bibliography.replace("\r\n", "\n", "g");
linebreak = "\n";
}
if(contents.indexOf(BIBLIOGRAPHY_PLACEHOLDER) !== -1) {
contents = contents.replace(BIBLIOGRAPHY_PLACEHOLDER, bibliography);
} else {
// add two newlines before bibliography
bibliography = linebreak+"\\"+linebreak+"\\"+bibliography;
// add bibliography automatically inside last set of brackets closed
const bracketRe = /^\{+/;
var m = bracketRe.exec(contents);
if(m) {
var closeBracketRe = new RegExp("(\\}{"+m[0].length+"}\\s*)$");
contents = contents.replace(closeBracketRe, bibliography+"\\1");
} else {
contents += bibliography;
}
}
}, "g");
}
Zotero.File.putContents(outputFile, contents);

View file

@ -15,7 +15,17 @@
<wizardpage id="intro-page" label="&zotero.rtfScan.introPage.label;"
onpageshow="Zotero_RTFScan.introPageShowing()"
onpageadvanced="Zotero_RTFScan.introPageAdvanced()">
<vbox>
<description width="700">&zotero.rtfScan.introPage.description;</description>
<label value="{Smith, 2009}"/>
<label value="Smith {2009}"/>
<label value="{Smith et al., 2009}"/>
<label value="{John Smith, 2009}"/>
<label value="{Smith, 2009, 10-14}"/>
<label value="{Smith, &quot;Title,&quot; 2009}"/>
<label value="{Jones, 2005; Smith, 2009}"/>
<description width="700" style="padding-top:1em">&zotero.rtfScan.introPage.description2;</description>
</vbox>
<groupbox>
<caption label="&zotero.rtfScan.inputFile.label;"/>
<hbox align="center">

View file

@ -188,7 +188,8 @@
<!ENTITY zotero.rtfScan.ambiguousCitations.label "Ambiguous Citations">
<!ENTITY zotero.rtfScan.mappedCitations.label "Mapped Citations">
<!ENTITY zotero.rtfScan.introPage.label "Introduction">
<!ENTITY zotero.rtfScan.introPage.description "Zotero can automatically extract and reformat citations and insert a bibliography into RTF files. To get started, choose an RTF file below.">
<!ENTITY zotero.rtfScan.introPage.description "Zotero can automatically extract and reformat citations and insert a bibliography into RTF files. The RTF Scan feature currently supports citations in variations upon the following formats:">
<!ENTITY zotero.rtfScan.introPage.description2 "To get started, select an RTF input file and an output file below:">
<!ENTITY zotero.rtfScan.scanPage.label "Scanning for Citations">
<!ENTITY zotero.rtfScan.scanPage.description "Zotero is scanning your document for citations. Please be patient.">
<!ENTITY zotero.rtfScan.citationsPage.label "Verify Cited Items">

View file

@ -539,6 +539,7 @@ rtfScan.scanning.label = Scanning RTF Document...
rtfScan.saving.label = Formatting RTF Document...
rtfScan.rtf = Rich Text Format (.rtf)
rtfScan.saveTitle = Select a location in which to save the formatted file
rtfScan.scannedFileSuffix = (Scanned)
lookup.failure.title = Lookup Failed
lookup.failure.description = Zotero could not find a record for the specified identifier. Please verify the identifier and try again.