Optional elements cannot be nested

Issue #43 resolved
Former user created an issue

I'm using the 0.15 release and have found that when writing styles it is not possible to nest optional elements. What I would like to do is:

optional [field('volume'), optional['(', field('number'), ')']]

However I get an error when I try to run that and the inner optional field "number" is not in the BibTeX record. The issue is that the optional function returns None if the field does not exist and this None gets added to the list of elements in the Text, which when rendering causes an exception. A fix that works for me is to update the Text class to filter out all None elements when it is initialised:

class Text(list): def __init__(self, *parts): """Create a Text consisting of one or more parts.""" list.__init__(self, filter(lambda p: p, parts))

Regards, Mark

Comments (2)

  1. Log in to comment