code: def format_str(
      src: str,
  ) -> tuple[str, Sequence[CodeBlockError]]:
      errors: list[CodeBlockError] = []
  
      @contextlib.contextmanager
      def _collect_error(
          match: Match[str],
      ) -> Generator[None, None, None]:
          try:
              yield
          except Exception as e:
              errors.append(CodeBlockError(match.start(), e))
  
      def _md_match(match: Match[str]) -> str:
          code = textwrap.dedent(match["code"])
          with _collect_error(match):
              code = format_code_block(code)
          code = textwrap.indent(code, match["indent"])
          return f'{match["before"]}{code}{match["after"]}'
  
      def _pycon_match(match: Match[str]) -> str:
          code = ""
          fragment = cast(Optional[str], None)
  
          def finish_fragment() -> None:
              nonlocal code
              nonlocal fragment
  
              if fragment is not None:
                  with _collect_error(match):
                      fragment = format_code_block(fragment)
                  fragment_lines = fragment.splitlines()
                  code += f"{PYCON_PREFIX}{fragment_lines[0]}\n"
                  for line in fragment_lines[1:]:
                      # Skip blank lines to handle Black adding a blank above
                      # functions within blocks. A blank line would end the REPL
                      # continuation prompt.
                      #
                      # >>> if True:
                      # ...     def f():
                      # ...         pass
                      # ...
                      if line:
                          code += (
                              f"{PYCON_CONTINUATION_PREFIX} {line}\n"
                          )
                  if fragment_lines[-1].startswith(" "):
                      code += f"{PYCON_CONTINUATION_PREFIX}\n"
                  fragment = None
  
          indentation = None
          for line in match["code"].splitlines():
              orig_line, line = line, line.lstrip()
              if indentation is None and line:
                  indentation = len(orig_line) - len(line)
              continuation_match = PYCON_CONTINUATION_RE.match(line)
              if continuation_match and fragment is not None:
                  fragment += line[continuation_match.end() :] + "\n"
              else:
                  finish_fragment()
                  if line.startswith(PYCON_PREFIX):
                      fragment = line[len(PYCON_PREFIX) :] + "\n"
                  else:
                      code += orig_line[indentation:] + "\n"
          finish_fragment()
          return code
  
      def _md_pycon_match(match: Match[str]) -> str:
          code = _pycon_match(match)
          code = textwrap.indent(code, match["indent"])
          return f'{match["before"]}{code}{match["after"]}'
  
      src = MD_RE.sub(_md_match, src)
      src = MD_PYCON_RE.sub(_md_pycon_match, src)
      return src, errors
  
file_path: openai-python/bin/ruffen-docs.py
imports: from __future__ import annotations
  import re
  import sys
  import argparse
  import textwrap
  import contextlib
  import subprocess
  from typing import Match, Optional, Sequence, Generator, NamedTuple, cast
label_desc: Use image node_id 1 for calling a global function with example usage: format_str(src) and returns: src,  errors, match, code, match, code, match, code, match