def core_module_docstrings(include_core=True, include_user=False, config=None, format="md"):
    """
    Get docstrings for all core modules and user ones if requested
    returns a dict of {<module_name>: <docstring>}
    """
    paths = {}
    docstrings = {}
    if include_core:
        for file in modules_directory().iterdir():
            if file.suffix == ".py":
                if file.stem != "__init__":
                    paths[file.stem] = (file, "core")

    if include_user:
        # include user modules
        for include_path in sorted(config["include_paths"]):
            for file in sorted(include_path.iterdir()):
                if file.suffix != ".py":
                    continue
                paths[file.stem] = (file, "user")
    for name in paths:
        path, module_type = paths[name]
        with path.open() 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

    Get docstrings for all core modules and user ones if requested
    returns a dict of {<module_name>: <docstring>}
    
py3status/docstrings.py