sergiocorreia / panflute

An Pythonic alternative to John MacFarlane's pandocfilters, with extra helper functions
http://scorreia.com/software/panflute/
BSD 3-Clause "New" or "Revised" License
500 stars 59 forks source link

Creating a Table without a Caption produces error #209

Closed jeffvalk closed 2 years ago

jeffvalk commented 2 years ago

It is not currently possible to create a Table without a caption. Doing so results in error:

# These both fail
Table(body, head=head)
Table(body, head=head, caption=None)

# This works
Table(body, head=head, caption=Caption())

The specific error is Element "Table" received "NoneType" but expected <class 'panflute.table_elements.Caption'>, which arises from this line in the constructor: https://github.com/sergiocorreia/panflute/blob/354297b90b763f99dee270b9e180baa21187cd64/panflute/table_elements.py#L74

A potential fix would be to only invoke the self.caption setter if the caption keyword argument is truthy.

jacobwhall commented 2 years ago

Hey @jeffvalk, I fixed this issue in #215, and @sergiocorreia just released v2.1.4 with the updated code. We should be able to close this issue now. Let me know if you have any more trouble!