@@ -1143,24 +1143,31 @@ def overview2md(self, is_mdx: bool = False) -> str:
11431143 modules = modules_md , classes = classes_md , functions = functions_md
11441144 )
11451145
1146- def toc2md (self , module : types .ModuleType = None , is_mdx : bool = False ) -> str :
1147- """Generates table of contents for imported object."""
1146+ def toc2md (self , module : types .ModuleType , is_mdx : bool = False ) -> str :
1147+ """Generates table of contents for imported object.
1148+
1149+ Args:
1150+ module (ModuleType): Parsed module object for TOC generation.
1151+ is_mdx (bool, optional): JSX support. Default to False.
1152+
1153+ Returns:
1154+ str: Markdown documentation of TOC file if TOC exist.
1155+ """
11481156 toc = []
11491157 for obj in self .generated_objects :
11501158 if module and (module .__name__ != obj ["module" ] or obj ["type" ] == "module" ):
11511159 continue
1152- # module_name = obj["module"].split(".")[-1]
11531160 full_name = obj ["full_name" ]
11541161 name = obj ["name" ]
1155- if is_mdx :
1156- link = "./" + obj ["module" ] + ".mdx#" + obj ["anchor_tag" ]
1157- else :
1158- link = "./" + obj ["module" ] + ".md#" + obj ["anchor_tag" ]
1159- line = f"- [`{ name } `]({ link } )"
1162+ summary = obj ["description" ]
1163+ link = f"./{ obj ['module' ]} .md{ 'x' if is_mdx else '' } #{ obj ['anchor_tag' ]} "
1164+ line = f"- [`{ name } `]({ link } ){ ': ' if summary else '' } { summary } "
11601165 depth = max (len (full_name .split ("." )) - 1 , 0 )
11611166 if depth :
11621167 line = "\t " * depth + line
11631168 toc .append (line )
1169+ if not toc :
1170+ return ""
11641171 return _TOC_TEMPLATE .format (toc = "\n " .join (toc ))
11651172
11661173
@@ -1193,6 +1200,7 @@ def generate_docs(
11931200 watermark: If `True`, add a watermark with a timestamp to bottom of the markdown files.
11941201 validate: If `True`, validate the docstrings via pydocstyle. Requires pydocstyle to be installed.
11951202 private_modules: If `True`, includes modules with `_` prefix.
1203+ include_toc: Include table of contents in module file. Defaults to False.
11961204 url_line_prefix: Line prefix for git repository line url anchors. Default: None - github "L".
11971205 """
11981206 stdout_mode = output_path .lower () == "stdout"
@@ -1369,7 +1377,7 @@ def generate_docs(
13691377 + repr (ex )
13701378 )
13711379 else :
1372- import_md = generator .import2md (obj , is_mdx = is_mdx )
1380+ import_md = generator .import2md (obj , is_mdx = is_mdx , include_toc = include_toc )
13731381 if stdout_mode :
13741382 print (import_md )
13751383 else :
0 commit comments