Skip to content

Commit

Permalink
add option to use a custom html field generation method (#1038)
Browse files Browse the repository at this point in the history
* add option to use a value's html field generation method

* update CHANGELOG.md

* update html representation docstring

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: Ryan Ly <rly@lbl.gov>
  • Loading branch information
stephprince and rly committed Feb 9, 2024
1 parent 8ad4db2 commit 0998190
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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)
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

0 comments on commit 0998190

Please sign in to comment.