Browse Source

fix regression in latex2html

pull/63/merge
Martin Monperrus 9 years ago
parent
commit
6a54d0b2ec
  1. 4
      bibtexbrowser-test.php
  2. 26
      bibtexbrowser.php

4
bibtexbrowser-test.php

@ -293,7 +293,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
} }
function test_BIBTEXBROWSER_USE_LATEX2HTML() { function test_BIBTEXBROWSER_USE_LATEX2HTML() {
$bibtex = "@article{aKey,title={\`a Book},author={Martin Monperrus},publisher={Springer},year=2009,pages={42--4242},number=1}\n";
$bibtex = "@article{aKey,title={\`a Book},author={J\'e Lo},publisher={Springer},year=2009,pages={42--4242},number=1}\n";
bibtexbrowser_configure('BIBTEXBROWSER_USE_LATEX2HTML', true); bibtexbrowser_configure('BIBTEXBROWSER_USE_LATEX2HTML', true);
$test_data = fopen('php://memory','x+'); $test_data = fopen('php://memory','x+');
@ -303,6 +303,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$db->update_internal("inline", $test_data); $db->update_internal("inline", $test_data);
$dis = $db->getEntryByKey('aKey'); $dis = $db->getEntryByKey('aKey');
$this->assertEquals("à Book",$dis->getTitle()); $this->assertEquals("à Book",$dis->getTitle());
$this->assertEquals("Jé Lo",$dis->getFormattedAuthorsString());
bibtexbrowser_configure('BIBTEXBROWSER_USE_LATEX2HTML', false); bibtexbrowser_configure('BIBTEXBROWSER_USE_LATEX2HTML', false);
$test_data = fopen('php://memory','x+'); $test_data = fopen('php://memory','x+');
@ -312,6 +313,7 @@ class BTBTest extends PHPUnit_Framework_TestCase {
$db->update_internal("inline", $test_data); $db->update_internal("inline", $test_data);
$dis = $db->getEntryByKey('aKey'); $dis = $db->getEntryByKey('aKey');
$this->assertEquals("\`a Book",$dis->getTitle()); $this->assertEquals("\`a Book",$dis->getTitle());
$this->assertEquals("J\'e Lo",$dis->getFormattedAuthorsString());
} }

26
bibtexbrowser.php

@ -1189,15 +1189,18 @@ class BibEntry {
} }
function transformValue($value) { function transformValue($value) {
// trim space
$value = xtrim($value);
if (c('BIBTEXBROWSER_USE_LATEX2HTML'))
{
// trim space
$value = xtrim($value);
// transform Latex markup to HTML entities (easier than a one to one mapping to each character)
// HTML entity is an intermediate format
$value = latex2html($value);
// transform to the target output encoding
$value = html_entity_decode($value, ENT_QUOTES|ENT_XHTML, OUTPUT_ENCODING);
// transform Latex markup to HTML entities (easier than a one to one mapping to each character)
// HTML entity is an intermediate format
$value = latex2html($value);
// transform to the target output encoding
$value = html_entity_decode($value, ENT_QUOTES|ENT_XHTML, OUTPUT_ENCODING);
}
return $value; return $value;
} }
@ -1210,11 +1213,8 @@ class BibEntry {
// we assume that "comment" is never latex code // we assume that "comment" is never latex code
// but instead could contain HTML code (with links using the character "~" for example) // but instead could contain HTML code (with links using the character "~" for example)
// so "comment" is not transformed too // so "comment" is not transformed too
if ($name!='url' && $name!='comment') {
if (c('BIBTEXBROWSER_USE_LATEX2HTML')) {
if ($name!='url' && $name!='comment') {
$value = $this->transformValue($value); $value = $this->transformValue($value);
}
// 4. transform existing encoded character in the new format // 4. transform existing encoded character in the new format
if (function_exists('mb_convert_encoding') && OUTPUT_ENCODING != BIBTEX_INPUT_ENCODING) { if (function_exists('mb_convert_encoding') && OUTPUT_ENCODING != BIBTEX_INPUT_ENCODING) {
@ -3804,7 +3804,7 @@ class BibDataBase {
/** Adds a new bib entry to the database. */ /** Adds a new bib entry to the database. */
function addEntry($entry) { function addEntry($entry) {
if (!$entry->hasField('key')) { if (!$entry->hasField('key')) {
die('error: a bibliographic entry must have a key '.$entry->getText());
throw new Exception('error: a bibliographic entry must have a key '.$entry->getText());
} }
// we keep its insertion order // we keep its insertion order
$entry->order = count($this->bibdb); $entry->order = count($this->bibdb);

Loading…
Cancel
Save