haive.core.utils.mermaid_utils

Mermaid diagram utilities for Haive.

This module provides utilities for generating and displaying Mermaid diagrams in different environments, with fallback mechanisms.

Classes

Environment

Execution environment types.

Functions

detect_environment()

Detect the current execution environment.

display_mermaid(mermaid_code[, output_path, save_png, ...])

Display a Mermaid diagram in the current environment.

mermaid_to_png(mermaid_code[, output_path])

Convert Mermaid diagram code to a PNG file.

Module Contents

class haive.core.utils.mermaid_utils.Environment[source]

Bases: str, enum.Enum

Execution environment types.

Initialize self. See help(type(self)) for accurate signature.

haive.core.utils.mermaid_utils.detect_environment()[source]

Detect the current execution environment.

Returns:

Environment enum indicating the detected environment

Return type:

Environment

haive.core.utils.mermaid_utils.display_mermaid(mermaid_code, output_path=None, save_png=False, width='100%')[source]

Display a Mermaid diagram in the current environment.

This function detects the current environment and uses the appropriate method to display the diagram, with fallbacks for each environment.

Parameters:
  • mermaid_code (str) – Mermaid diagram code

  • output_path (str | None) – Optional path to save the diagram

  • save_png (bool) – Whether to save the diagram as PNG

  • width (str) – Width of the displayed diagram

Return type:

None

haive.core.utils.mermaid_utils.mermaid_to_png(mermaid_code, output_path=None)[source]

Convert Mermaid diagram code to a PNG file.

Parameters:
  • mermaid_code (str) – Mermaid diagram code as string

  • output_path (str | None) – Path to save the PNG file (auto-generated if not provided)

Returns:

Path to the generated PNG file, or None if conversion failed

Return type:

str | None