diff --git a/.travis.yml b/.travis.yml index 6a0982c..e524a05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: php php: 5.4 -script: phpunit bibtexbrowser-test.php +script: + - curl -o gakowiki-syntax.php http://www.monperrus.net/martin/gakowiki-syntax.php.txt + - phpunit bibtexbrowser-test.php -sudo: false \ No newline at end of file +sudo: false diff --git a/bibtexbrowser-documentation.wiki b/bibtexbrowser-documentation.wiki index 4d5a86e..0ec3ff6 100755 --- a/bibtexbrowser-documentation.wiki +++ b/bibtexbrowser-documentation.wiki @@ -503,7 +503,7 @@ You must add a ''@string'' block in the bibtex file, which contains the links. T hp_ericfoo = {http://www.foo.de/}, hp_joebar = {http://www.joebar.me/}, } - + =====Related tools===== diff --git a/bibtexbrowser-test.php b/bibtexbrowser-test.php index ae041a6..ac19d6c 100755 --- a/bibtexbrowser-test.php +++ b/bibtexbrowser-test.php @@ -21,6 +21,11 @@ error_reporting(E_ALL); class BTBTest extends PHPUnit_Framework_TestCase { + function test_checkdoc() { + include('gakowiki-syntax.php'); + create_wiki_parser()->parse(file_get_contents('bibtexbrowser-documentation.wiki')); + } + function createDB() { $test_data = fopen('php://memory','x+'); fwrite($test_data, "@book{aKey,title={A Book},author={Martin Monperrus},publisher={Springer},year=2009}\n" @@ -445,7 +450,7 @@ class BTBTest extends PHPUnit_Framework_TestCase { $this->assertEquals("Meyer, Heribert and Foo Bar", $entry->getFormattedAuthorsString()); // Github issue 61 - $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 and J{\'e} Ko}}\n"; // wrong parsing of author names $test_data = fopen('php://memory','x+'); fwrite($test_data, $bibtex); @@ -454,10 +459,11 @@ class BTBTest extends PHPUnit_Framework_TestCase { $db->update_internal("inline", $test_data); $entry = $db->getEntryByKey('aKey61'); $authors = $entry->getRawAuthors(); - $this->assertEquals(3, count($authors)); + $this->assertEquals(4, count($authors)); $this->assertEquals("Meyer, Heribert", $authors[0]); $this->assertEquals("Advanced Air and Ground Research Team", $authors[1]); $this->assertEquals("Foo Bar", $authors[2]); + $this->assertEquals("Jé Ko", $authors[3]); } function test_latex2html() { diff --git a/bibtexbrowser.php b/bibtexbrowser.php index e413dd0..33b3626 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -910,6 +910,13 @@ class BibDBBuilder extends ParserDelegate { // to enable search if ($this->currentEntry->hasField('author')) { $this->currentEntry->setField(Q_INNER_AUTHOR,$this->currentEntry->getFormattedAuthorsString()); + + foreach($this->currentEntry->split_authors() as $author) { + $homepage_key = $this->currentEntry->getHomePageKey($author); + if (isset($this->stringdb[$homepage_key])) { + $this->currentEntry->homepages[$homepage_key] = $this->stringdb[$homepage_key]->value; + } + } } // ignoring jabref comments @@ -929,21 +936,6 @@ class BibDBBuilder extends ParserDelegate { $this->builtdb[$this->currentEntry->getKey()] = $this->currentEntry; } } - - - function entryValuePart($key, $value, $type) { - if (preg_match('/^author$/i',trim($key)) && strlen($value)>0) { - if ($type == 'CURLYTOP') { - foreach (preg_split('/\s+and\s+/i', $value) as $author) { - if (strlen($author)>0) { - $this->currentEntry->addAuthor($author, $this); - } - } - } else { // 'CURLYONE', nnon-breakable - $this->currentEntry->addAuthor($value, $this); - } - } - } } // end class BibDBBuilder @@ -1114,16 +1106,19 @@ notes: class BibEntry { /** The fields (fieldName -> value) of this bib entry. */ - var $fields; + var $fields = array(); /** The constants @STRINGS referred to by this entry */ - var $constants; + var $constants = array(); + + /** The homepages of authors if any */ + var $homepages = array(); /** The crossref entry if there is one */ var $crossref; /** The verbatim copy (i.e., whole text) of this bib entry. */ - var $text; + var $text = ''; /** A timestamp to trace when entries have been created */ var $timestamp; @@ -1140,9 +1135,6 @@ class BibEntry { /** The location in the original bibtex file (set by addEntry) */ var $order = -1; - /** the authors (split at parsing time) */ - var $author_array = array(); - /** returns a debug string representation */ function __toString() { @@ -1152,9 +1144,6 @@ class BibEntry { /** Creates an empty new bib entry. Each bib entry is assigned a unique * identification number. */ function BibEntry() { - $this->fields = array(); - $this->constants = array(); - $this->text =''; } /** Sets the name of the file containing this entry */ @@ -1210,9 +1199,9 @@ class BibEntry { $value = mb_convert_encoding($value, OUTPUT_ENCODING, BIBTEX_INPUT_ENCODING); } + // clean extra tex curly brackets, usually used for preserving capitals - $value = preg_replace('/^\{/','', $value); - $value = preg_replace('/\}$/','', $value); + $value = $this->clean_top_curly($value); } else { //echo "xx".$value."xx\n"; @@ -1222,6 +1211,12 @@ class BibEntry { $this->fields[$name] = $value; } + + function clean_top_curly($value) { + $value = preg_replace('/^\{/','', $value); + $value = preg_replace('/\}$/','', $value); + return $value; + } /** Sets a type of this bib entry. */ function setType($value) { @@ -1360,16 +1355,6 @@ class BibEntry { return isset($this->fields[strtolower($name)]); } - /** adds an author to this entry */ - function addAuthor($author, $db) { - $this->author_array[] = trim($author); - - $homepage_key = $this->getHomePageKey($author); - if (isset($db->stringdb[$homepage_key])) { - $this->constants[$homepage_key] = $db->stringdb[$homepage_key]->value; - } - } - /** Returns the authors of this entry. If "author" is not given, * return a string 'Unknown'. */ function getAuthor() { @@ -1420,7 +1405,25 @@ class BibEntry { /** Returns the authors of this entry as an array (split by " and ") */ function getRawAuthors() { - return $this->author_array; + return $this->split_authors(); + } + + function split_authors() { + $array = preg_split('/ and /i', $this->getField(Q_AUTHOR)); + $res = array(); + // we merge the remaining ones + for ($i=0; $i < count($array)-1; $i++) { + if (strpos( latex2html($array[$i]), '{') !== FALSE && strpos(latex2html($array[$i+1]),'}') !== FALSE) { + $res[] = $this->clean_top_curly($array[$i]." and ".$array[$i+1]); + $i = $i + 1; + } else { + $res[] = $array[$i]; + } + } + if (strpos($array[count($array)-1], '}')===FALSE) { + $res[] = $array[count($array)-1]; + } + return $res; } /** @@ -1482,6 +1485,7 @@ class BibEntry { function getFormattedAuthorsArray() { $array_authors = array(); + // first we use formatAuthor foreach ($this->getRawAuthors() as $author) { $array_authors[]=$this->formatAuthor($author); @@ -1574,8 +1578,8 @@ class BibEntry { // accents are normally handled // e.g. @STRING{hp_Jean-MarcJézéquel="http://www.irisa.fr/prive/jezequel/"} $homepage = $this->getHomePageKey($author); - if (isset($this->constants[$homepage])) - $author=''.$author.''; + if (isset($this->homepages[$homepage])) + $author=''.$author.''; return $author; } @@ -1841,7 +1845,6 @@ class BibEntry { function getConstants() { $result=''; foreach ($this->constants as $k=>$v) { - if (preg_match('/^hp_/',$k)) continue; $result.='@string{'.$k.'="'.$v."\"}\n"; } return $result;