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

add option to use a custom html field generation method #1038

Merged
merged 6 commits into from
Feb 9, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# HDMF Changelog

## HDMF 3.12.2 (February 9, 2024)

### Bug fixes
- Fixed recursion error in html representation generation in jupyter notebooks. @stephprince [#1038](https://github.com/hdmf-dev/hdmf/pull/1038)

## HDMF 3.12.1 (February 5, 2024)

### Bug fixes
Expand Down
10 changes: 8 additions & 2 deletions src/hdmf/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,10 @@ def _generate_html_repr(self, fields, level=0, access_code="", is_field=False):
if isinstance(fields, dict):
for key, value in fields.items():
current_access_code = f"{access_code}.{key}" if is_field else f"{access_code}['{key}']"
html_repr += self._generate_field_html(key, value, level, current_access_code)
if hasattr(value, '_generate_field_html'):
html_repr += value._generate_field_html(key, value, level, current_access_code)
else:
html_repr += self._generate_field_html(key, value, level, current_access_code)
rly marked this conversation as resolved.
Show resolved Hide resolved
elif isinstance(fields, list):
for index, item in enumerate(fields):
access_code += f'[{index}]'
Expand All @@ -639,7 +642,10 @@ def _generate_html_repr(self, fields, level=0, access_code="", is_field=False):
return html_repr

def _generate_field_html(self, key, value, level, access_code):
"""Generates HTML for a single field."""
"""Generates HTML for a single field.

This function can be overwritten by a child class to implement customized html representations.
"""

if isinstance(value, (int, float, str, bool)):
return f'<div style="margin-left: {level * 20}px;" class="container-fields"><span class="field-key"' \
Expand Down
Loading