Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure, Table: fix to_json() crash if caption is None #230

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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