feat: add support for Oxford commas in name lists (#95)
This commit is contained in:
committed by
Martin Monperrus
parent
5480c6d71b
commit
6c9daef93e
+11
-2
@@ -486,7 +486,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
function test_formatting() {
|
function test_formatting() {
|
||||||
|
|
||||||
$bibtex = "@article{aKey61,title={An article Book},author = {Meyer, Heribert and {Advanced Air and Ground Research Team} and Foo Bar}}\n";
|
$bibtex = "@article{aKey61,title={An article Book},author = {Meyer, Heribert and {Advanced Air and Ground Research Team} and Foo Bar}}\n@article{bKey61,title={An article Book},author = {Meyer, Heribert and Foo Bar}}\n";
|
||||||
$test_data = fopen('php://memory','x+');
|
$test_data = fopen('php://memory','x+');
|
||||||
fwrite($test_data, $bibtex);
|
fwrite($test_data, $bibtex);
|
||||||
fseek($test_data,0);
|
fseek($test_data,0);
|
||||||
@@ -531,7 +531,16 @@ class BTBTest extends PHPUnit_Framework_TestCase {
|
|||||||
$this->assertEquals("Advanced Air and Ground Research Team", $authors[1]);
|
$this->assertEquals("Advanced Air and Ground Research Team", $authors[1]);
|
||||||
$this->assertEquals("Foo Bar", $authors[2]);
|
$this->assertEquals("Foo Bar", $authors[2]);
|
||||||
$this->assertEquals("Heribert Meyer, Advanced Air and Ground Research Team and Foo Bar", $entry->getFormattedAuthorsString());
|
$this->assertEquals("Heribert Meyer, Advanced Air and Ground Research Team and Foo Bar", $entry->getFormattedAuthorsString());
|
||||||
|
|
||||||
|
// test Oxford comma with default options
|
||||||
|
bibtexbrowser_configure('USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT', false);
|
||||||
|
bibtexbrowser_configure('USE_INITIALS_FOR_NAMES', false);
|
||||||
|
bibtexbrowser_configure('USE_FIRST_THEN_LAST', false);
|
||||||
|
bibtexbrowser_configure('USE_OXFORD_COMMA', true);
|
||||||
|
$this->assertEquals("Meyer, Heribert, Advanced Air and Ground Research Team, and Foo Bar", $entry->getFormattedAuthorsString());
|
||||||
|
$entry = $db->getEntryByKey('bKey61');
|
||||||
|
$this->assertEquals("Meyer, Heribert and Foo Bar", $entry->getFormattedAuthorsString());
|
||||||
|
bibtexbrowser_configure('USE_OXFORD_COMMA', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_parsing_author_list() {
|
function test_parsing_author_list() {
|
||||||
|
|||||||
+8
-1
@@ -171,6 +171,7 @@ if (defined('ENCODING')) {
|
|||||||
@define('USE_FIRST_THEN_LAST',false); // put first names before last names?
|
@define('USE_FIRST_THEN_LAST',false); // put first names before last names?
|
||||||
@define('FORCE_NAMELIST_SEPARATOR', ''); // if non-empty, use this to separate multiple names regardless of USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT
|
@define('FORCE_NAMELIST_SEPARATOR', ''); // if non-empty, use this to separate multiple names regardless of USE_COMMA_AS_NAME_SEPARATOR_IN_OUTPUT
|
||||||
@define('LAST_AUTHOR_SEPARATOR',' and ');
|
@define('LAST_AUTHOR_SEPARATOR',' and ');
|
||||||
|
@define('USE_OXFORD_COMMA',false); // adds an additional separator in addition to LAST_AUTHOR_SEPARATOR if there are more than two authors
|
||||||
|
|
||||||
@define('TYPES_SIZE',10); // number of entry types per table
|
@define('TYPES_SIZE',10); // number of entry types per table
|
||||||
@define('YEAR_SIZE',20); // number of years per table
|
@define('YEAR_SIZE',20); // number of years per table
|
||||||
@@ -1570,7 +1571,13 @@ class BibEntry {
|
|||||||
for ($i=0;$i<count($authors)-2;$i++) {
|
for ($i=0;$i<count($authors)-2;$i++) {
|
||||||
$result .= $authors[$i].$sep;
|
$result .= $authors[$i].$sep;
|
||||||
}
|
}
|
||||||
$result .= $authors[count($authors)-2].bibtexbrowser_configuration('LAST_AUTHOR_SEPARATOR'). $authors[count($authors)-1];
|
$lastAuthorSeperator = bibtexbrowser_configuration('LAST_AUTHOR_SEPARATOR');
|
||||||
|
// add Oxford comma if there are more than 2 authors
|
||||||
|
if (bibtexbrowser_configuration('USE_OXFORD_COMMA') && count($authors)>2) {
|
||||||
|
$lastAuthorSeperator = $sep.$lastAuthorSeperator;
|
||||||
|
$lastAuthorSeperator = preg_replace("/ {2,}/", " ", $lastAuthorSeperator); // get rid of double spaces
|
||||||
|
}
|
||||||
|
$result .= $authors[count($authors)-2].$lastAuthorSeperator.$authors[count($authors)-1];
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user