code: def core_module_docstrings(
      include_core=True, include_user=False, config=None, format="md"
  ):
      
      paths = {}
      docstrings = {}
      if include_core:
          for file in os.listdir(modules_directory()):
              if file.endswith(".py"):
                  name = file[:-3]
                  if name != "__init__":
                      paths[name] = (os.path.join(modules_directory(), file), "core")
  
      if include_user:
          # include user modules
          for include_path in sorted(config["include_paths"]):
              for file in sorted(os.listdir(include_path)):
                  if not file.endswith(".py"):
                      continue
                  name = file[:-3]
                  paths[name] = (os.path.join(include_path, file), "user")
      for name in paths:
          path, module_type = paths[name]
          with open(path) as f:
              try:
                  module = ast.parse(f.read())
              except SyntaxError:
                  # there is a syntax error so ignore module
                  continue
              raw_docstring = ast.get_docstring(module)
  
              # prevent issue when no docstring exists
              if raw_docstring is None:
                  continue
  
              # remove any sample outputs
              parts = re.split("^SAMPLE OUTPUT$", raw_docstring, flags=re.M)
              docstring = parts[0]
  
              if format == "md":
                  docstring = [
                      d for d in _from_docstring_md(str(docstring).strip().split("\n"))
                  ]
              elif format == "rst":
                  docstring = [
                      d for d in _from_docstring_rst(str(docstring).strip().split("\n"))
                  ]
              else:
                  raise Exception("`md` and `rst` format supported only")
  
              docstrings[name] = docstring + ["\n"]
      return docstrings
docs: Get docstrings for all core modules and user ones if requested
      returns a dict of {<module_name>: <docstring>}