code: def _to_mermaid_text(graph: networkx.MultiDiGraph) -> str:
      """
      Converts a Networkx graph into Mermaid syntax. The output of this function can be used in the documentation
      with `mermaid` codeblocks and it will be automatically rendered.
      """
      sockets = {
          comp: "".join(
              [
                  f"<li>{name} ({_type_name(socket.type)})</li>"
                  for name, socket in data.get(
                      "input_sockets", {}
                  ).items()
                  if (not socket.is_mandatory and not socket.senders)
                  or socket.is_variadic
              ]
          )
          for comp, data in graph.nodes(data=True)
      }
      optional_inputs = {
          comp: f"<br><br>Optional inputs:<ul style='text-align:left;'>{sockets}</ul>"
          if sockets
          else ""
          for comp, sockets in sockets.items()
      }
  
      states = {
          comp: f"{comp}[\"<b>{comp}</b><br><small><i>{type(data['instance']).__name__}{optional_inputs[comp]}</i></small>\"]:::component"
          for comp, data in graph.nodes(data=True)
          if comp not in ["input", "output"]
      }
  
      connections_list = []
      for from_comp, to_comp, conn_data in graph.edges(data=True):
          if from_comp != "input" and to_comp != "output":
              arrowtail = (
                  ARROWTAIL_MANDATORY
                  if conn_data["mandatory"]
                  else ARROWTAIL_OPTIONAL
              )
              arrowhead = (
                  ARROWHEAD_MANDATORY
                  if conn_data["mandatory"]
                  else ARROWHEAD_OPTIONAL
              )
              label = f'"{conn_data["label"]}<br><small><i>{conn_data["conn_type"]}</i></small>"'
              conn_string = f"{states[from_comp]} {arrowtail} {label} {arrowhead} {states[to_comp]}"
              connections_list.append(conn_string)
  
      input_connections = [
          f"i{{*}} -- \"{conn_data['label']}<br><small><i>{conn_data['conn_type']}</i></small>\" --> {states[to_comp]}"
          for _, to_comp, conn_data in graph.out_edges(
              "input", data=True
          )
      ]
      output_connections = [
          f"{states[from_comp]} -- \"{conn_data['label']}<br><small><i>{conn_data['conn_type']}</i></small>\"--> o{{*}}"
          for from_comp, _, conn_data in graph.in_edges(
              "output", data=True
          )
      ]
      connections = "\n".join(
          connections_list + input_connections + output_connections
      )
  
      graph_styled = MERMAID_STYLED_TEMPLATE.format(
          connections=connections
      )
      logger.debug("Mermaid diagram:\n%s", graph_styled)
  
      return graph_styled
  
imports: import logging
  import base64
  import requests
  import networkx
  from haystack.core.errors import PipelineDrawingError
  from haystack.core.type_utils import _type_name
label_desc: Use image node_id 2 for calling a global function with example usage: _to_mermaid_text(graph) and returns: graph_styled