Figure, Table: to_json() crashes if caption is None
Closed this issue · 1 comments
garethstockwell commented
Test program:
#!/usr/bin/env python3
from panflute import Caption, Figure, Image, Para, Plain, Str
from panflute import Table, TableBody, TableCell, TableRow
figure = Figure(Plain(Image()))
print(figure.to_json())
table = Table(TableBody(TableRow(TableCell(Para(Str('foo'))))))
print(table.to_json())
With panflute c4e8125, this produces:
Traceback (most recent call last):
File "./test_caption.py", line 7, in <module>
print(figure.to_json())
File "/home/gareth/panflute/panflute/base.py", line 84, in to_json
return encode_dict(self.tag, self._slots_to_json())
File "/home/gareth/panflute/panflute/elements.py", line 1056, in _slots_to_json
return [self._ica_to_json(), self.caption.to_json(), self.content.to_json()]
AttributeError: 'NoneType' object has no attribute 'to_json'
TheDarkTrumpet commented
I also ran into the same thing this morning. Trying something along the lines of:
row = pf.TableRow(*[
pf.TableCell(pf.Para(pf.Str(narrative)), alignment="AlignLeft"),
pf.TableCell(pf.Para(pf.Image(url="histograms.png")))
]
)
body = pf.TableBody(row)
table = pf.Table(body, caption=None)
return table