def struct_attr_style_fn_for_fields(
    fields,
) -> Callable[[str], rendering_parts.RenderableTreePart]:
  """Builds a function to render attributes of a struct.

  The resulting function will render pytree node fields in a different style.

  Args:
    fields: The fields of the struct.

  Returns:
    A function that takes a field name and returns a RenderableTreePart for the
    attribute rendering.
  """
  fields_by_name = {field.name: field for field in fields}

  def attr_style_fn(field_name):
    if struct.is_pytree_node_field(fields_by_name[field_name]):
      return rendering_parts.custom_style(
          rendering_parts.text(field_name),
          css_style="font-style: italic; color: #00225f;",
      )
    else:
      return rendering_parts.text(field_name)

  return attr_style_fn
Builds a function to render attributes of a struct.

  The resulting function will render pytree node fields in a different style.

  Args:
    fields: The fields of the struct.

  Returns:
    A function that takes a field name and returns a RenderableTreePart for the
    attribute rendering.
  
penzai/core/_treescope_handlers/struct_handler.py