7777CODE_SPAN_RE = re .compile (r"(`+)(.+?)\1" , re .DOTALL )
7878MODULE_PREFIX_RE = re .compile (r"\blightpanda\.\w+\." )
7979LINK_RE = re .compile (r"\]\(#([a-z0-9-]+)\)" )
80+ SECTION_RE = re .compile (r"^#{2,6} (\w+):$" , re .MULTILINE )
81+ LIST_ITEM_RE = re .compile (r"^\s*[-*] " )
82+ DOCFORMAT = getattr (lightpanda , "__docformat__" , "restructuredtext" )
8083
8184
8285def slug (* parts : str ) -> str :
@@ -132,6 +135,7 @@ def fence_indented_blocks(text: str) -> str:
132135 out : list [str ] = []
133136 block : list [str ] = []
134137 in_fence = False
138+ in_list = False # indented lines inside a list are item continuations
135139
136140 def flush () -> None :
137141 if block :
@@ -149,11 +153,16 @@ def flush() -> None:
149153 flush ()
150154 in_fence = not in_fence
151155 out .append (line )
152- elif not in_fence and line .startswith (" " ) and line .strip ():
156+ elif not in_fence and line .startswith (" " ) and line .strip () and not in_list :
153157 block .append (line .rstrip ())
154158 else :
155159 flush ()
156160 out .append (line )
161+ if not in_fence :
162+ if LIST_ITEM_RE .match (line ):
163+ in_list = True
164+ elif not line .strip ():
165+ in_list = False
157166 flush ()
158167 return "\n " .join (out )
159168
@@ -180,7 +189,10 @@ def render_docstring(doc: pdoc.doc.Doc, links: dict[str, str]) -> str:
180189 raw = doc .docstring
181190 if not raw .strip ():
182191 return ""
183- text = pdoc .docstrings .convert (raw , "restructuredtext" , doc .source_file )
192+ text = pdoc .docstrings .convert (raw , DOCFORMAT , doc .source_file )
193+ # pdoc renders Google-style sections (Args, Returns, ...) as headings;
194+ # keep them out of the page's outline.
195+ text = SECTION_RE .sub (r"**\1:**" , text )
184196 text = fence_indented_blocks (text )
185197 out : list [str ] = []
186198 prose : list [str ] = []
0 commit comments