Skip to content

Commit

Permalink
Merge pull request #230 from garethstockwell/dev
Browse files Browse the repository at this point in the history
Figure, Table: fix to_json() crash if caption is None
  • Loading branch information
sergiocorreia authored Mar 20, 2024
2 parents 582353b + 915b310 commit e580ea5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions panflute/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,11 @@ def caption(self):

@caption.setter
def caption(self, value):
self._caption = check_type_or_value(value, Caption, None)
if self._caption is not None:
self._caption.parent = self
self._caption.location = 'caption'
if value is None:
value = Caption()
self._caption = check_type(value, Caption)
self._caption.parent = self
self._caption.location = 'caption'

def _slots_to_json(self):
return [self._ica_to_json(), self.caption.to_json(), self.content.to_json()]
Expand Down
9 changes: 5 additions & 4 deletions panflute/table_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ def caption(self):

@caption.setter
def caption(self, value):
self._caption = check_type_or_value(value, Caption, None)
if self._caption is not None:
self._caption.parent = self
self._caption.location = 'caption'
if value is None:
value = Caption()
self._caption = check_type(value, Caption)
self._caption.parent = self
self._caption.location = 'caption'

def _slots_to_json(self):
ica = self._ica_to_json()
Expand Down

0 comments on commit e580ea5

Please sign in to comment.