code: def format_config_rst(config):
      attrs = config_attrs(config)
  
      def join(elements):
          return "\n\n\n".join(e for e in elements if e)
  
      bases = [
          Config.from_config(base) for base in config.config.__bases__
      ]
  
      config_doc = "\n".join(
          (
              f".. py:currentmodule:: {config.config.__module__}",
              f".. py:class:: {config.config.__name__}",
              I(1) + ":noindex:",
              "",
              I(1)
              + "**Bases:** "
              + ", ".join(
                  f":class:`{base.name} <{base.path}>`\\ "
                  for base in bases
              ),
              "",
              *(
                  I(1) + line
                  for line in GoogleDocstring(
                      unindent_docstring(config.config.__doc__ or "")
                  ).lines()
              ),
              "",
              "**All Attributes (including base classes)**",
              "",
              *itertools.chain.from_iterable(
                  (
                      I(1)
                      + f"**{attr.name}**: {marked_up_type_name(attr.type)}"
                      + (
                          f" = {marked_up_default_value(attr.default)}"
                          if attr.default is not NO_DEFAULT
                          else ""
                      ),
                      *(
                          I(2) + line
                          for line in attr.docstring or ("\\ ",)
                      ),
                      "",
                  )
                  for attr in attrs
              ),
          )
      )
  
      try:
          config_json = json.dumps(
              config_to_json(config.config, config.config()), indent=4
          )
      except Exception as e:
          print(e)
          config_json = ""
  
      subclasses = sorted(
          subclass_configs(config.config), key=lambda c: c.path
      )
  
      return join(
          (
              rst_big_header(config.config.__name__),
              *(
                  (
                      f"**Component:** :class:`{config.config.__COMPONENT__.__name__} "
                      + f" <{canonical_path(config.config.__COMPONENT__)}>`\ ",
                  )
                  if hasattr(config.config, "__COMPONENT__")
                  else ()
              ),
              config_doc,
              "\n".join(
                  (
                      "**Subclasses**",
                      *(
                          I(1)
                          + f"- :class:`{child.name} <{child.path}>`\\ "
                          for child in subclasses
                      ),
                  )
              )
              if hasattr(config.config, "__EXPANSIBLE__") and subclasses
              else "",
              *(
                  (
                      "**Default JSON**",
                      ".. code-block:: json",
                      "\n".join(
                          I(1) + line
                          for line in config_json.split("\n")
                      ),
                  )
                  if config_json
                  else (
                      "\n".join(
                          (
                              ".. warning::",
                              I(1)
                              + "This config has parameters with no default values.",
                              I(1)
                              + "We aren't yet able to generate functional JSON for it.",
                          )
                      ),
                  )
              ),
          )
      )
  
imports: import collections
  import contextlib
  import itertools
  import json
  import os
  import typing
  from pytext.config import ConfigBase, ExportConfig, PyTextConfig
  from pytext.config.component import Registry
  from pytext.config.serialize import config_to_json
  from pytext.utils.file_io import PathManager
  from sphinx.ext.napoleon import GoogleDocstring
  from sphinx.pycode import ModuleAnalyzer
label_desc: Use image node_id 12 for calling a global function with example usage: format_config_rst(config) and returns: join, str