Fix 177: convert latex to unicode before printing one-liner.
This commit actually introduces a new method on the paper object to return a copy of the bibdata which entries' latex have been converted to unicode.
This commit is contained in:
parent
3fa1604155
commit
fbc9b94f8d
@ -1,6 +1,8 @@
|
|||||||
import copy
|
import copy
|
||||||
from dateutil.parser import parse as datetime_parse
|
from dateutil.parser import parse as datetime_parse
|
||||||
|
|
||||||
|
from bibtexparser.customization import convert_to_unicode
|
||||||
|
|
||||||
from . import bibstruct
|
from . import bibstruct
|
||||||
from .p3 import ustr
|
from .p3 import ustr
|
||||||
|
|
||||||
@ -102,6 +104,10 @@ class Paper(object):
|
|||||||
def added(self, value):
|
def added(self, value):
|
||||||
self.metadata['added'] = value
|
self.metadata['added'] = value
|
||||||
|
|
||||||
|
def get_unicode_bibdata(self):
|
||||||
|
"""Converts latex in bibdata fields to unicode."""
|
||||||
|
return convert_to_unicode(self.bibdata)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_bibentry(bibentry, citekey=None, metadata=None):
|
def from_bibentry(bibentry, citekey=None, metadata=None):
|
||||||
bibentry_key, bibdata = bibstruct.get_entry(bibentry)
|
bibentry_key, bibdata = bibstruct.get_entry(bibentry)
|
||||||
|
@ -64,7 +64,7 @@ def paper_oneliner(p, citekey_only=False):
|
|||||||
if citekey_only:
|
if citekey_only:
|
||||||
return p.citekey
|
return p.citekey
|
||||||
else:
|
else:
|
||||||
bibdesc = bib_oneliner(p.bibdata)
|
bibdesc = bib_oneliner(p.get_unicode_bibdata())
|
||||||
doc_str = ''
|
doc_str = ''
|
||||||
if p.docpath is not None:
|
if p.docpath is not None:
|
||||||
doc_extension = os.path.splitext(p.docpath)[1]
|
doc_extension = os.path.splitext(p.docpath)[1]
|
||||||
|
@ -84,6 +84,18 @@ not_bibtex = """@misc{this looks,
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
bibtex_with_latex = """@article{kjaer2018large,
|
||||||
|
title={A large impact crater beneath Hiawatha Glacier in northwest Greenland},
|
||||||
|
author={Kj{\\ae}r, Kurt H and Larsen, Nicolaj K and Binder, Tobias and Bj{\\o}rk, Anders A and Eisen, Olaf and Fahnestock, Mark A and Funder, Svend and Garde, Adam A and Haack, Henning and Helm, Veit and others},
|
||||||
|
journal={Science advances},
|
||||||
|
volume={4},
|
||||||
|
number={11},
|
||||||
|
pages={eaar8173},
|
||||||
|
year={2018},
|
||||||
|
publisher={American Association for the Advancement of Science}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
sample_conf = """
|
sample_conf = """
|
||||||
[main]
|
[main]
|
||||||
|
|
||||||
|
@ -4,7 +4,9 @@ import unittest
|
|||||||
|
|
||||||
import dotdot
|
import dotdot
|
||||||
import fixtures
|
import fixtures
|
||||||
|
import str_fixtures
|
||||||
from pubs.paper import Paper
|
from pubs.paper import Paper
|
||||||
|
from pubs.endecoder import EnDecoder
|
||||||
|
|
||||||
|
|
||||||
class TestAttributes(unittest.TestCase):
|
class TestAttributes(unittest.TestCase):
|
||||||
@ -47,5 +49,20 @@ class TestAttributes(unittest.TestCase):
|
|||||||
Paper(" ", fixtures.doe_bibdata)
|
Paper(" ", fixtures.doe_bibdata)
|
||||||
|
|
||||||
|
|
||||||
|
class TestPaperUnicodeBibdata(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_no_latex(self):
|
||||||
|
p = Paper.from_bibentry(fixtures.page_bibentry,
|
||||||
|
metadata=fixtures.page_metadata).deepcopy()
|
||||||
|
self.assertEqual(p.bibdata, p.get_unicode_bibdata())
|
||||||
|
|
||||||
|
def test_latex_converted(self):
|
||||||
|
bib = EnDecoder().decode_bibdata(str_fixtures.bibtex_with_latex)
|
||||||
|
p = Paper.from_bibentry(bib)
|
||||||
|
ubib = p.get_unicode_bibdata()
|
||||||
|
self.assertEqual(ubib['author'][0], "Kjær, Kurt H")
|
||||||
|
self.assertEqual(ubib['author'][3], "Bjørk, Anders A")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user