class_docstr: Stores some state that persists between recursions into the element tree
docstr: Used when we encounter the same token twice in the same tree. When this
  happens, we replace all instances of that token with a terminal, and
  create a new subdiagram for the token
code: def extract_into_diagram(self, el_id: int):
      """
      Used when we encounter the same token twice in the same tree. When this
      happens, we replace all instances of that token with a terminal, and
      create a new subdiagram for the token
      """
      position = self[el_id]
  
      # Replace the original definition of this element with a regular block
      if position.parent:
          ret = EditablePartial.from_call(
              railroad.NonTerminal, text=position.name
          )
          if "item" in position.parent.kwargs:
              position.parent.kwargs["item"] = ret
          elif "items" in position.parent.kwargs:
              position.parent.kwargs["items"][
                  position.parent_index
              ] = ret
  
      # If the element we're extracting is a group, skip to its content but keep the title
      if position.converted.func == railroad.Group:
          content = position.converted.kwargs["item"]
      else:
          content = position.converted
  
      self.diagrams[el_id] = EditablePartial.from_call(
          NamedDiagram,
          name=position.name,
          diagram=EditablePartial.from_call(
              railroad.Diagram, content, **self.diagram_kwargs
          ),
          index=position.number,
      )
  
      del self[el_id]
  
imports: import railroad
  import pyparsing
  import typing
  from typing import List, NamedTuple, Generic, TypeVar, Dict, Callable, Set, Iterable
  from jinja2 import Template
  from io import StringIO
  import inspect
label_desc: Use image node_id 8 for calling the ConverterState obj's underlying member method code with example usage: obj.extract_into_diagram(el_id) without return types