Skip to content

Figure, Table: to_json() crashes if caption is None #229

@garethstockwell

Description

@garethstockwell

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'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions