Skip to content

Commit 7222477

Browse files
committed
BUG: Fix return types shown in bold (like names) for Google style
Fixes #146
1 parent 65dcea3 commit 7222477

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

pdoc/html_helpers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,20 @@ def googledoc_sections(match):
243243
return match.group()
244244
body = textwrap.dedent(body)
245245
section = section.title()
246-
if section in ('Args', 'Attributes', 'Returns', 'Yields', 'Raises', 'Warns'):
246+
if section in ('Args', 'Attributes'):
247247
body = re.compile(
248248
r'^([\w*]+)(?: \(([\w.,=\[\] ]+)\))?: '
249249
r'((?:.*)(?:\n(?: {2,}.*|$))*)', re.MULTILINE).sub(
250250
lambda m: _ToMarkdown._deflist(*_ToMarkdown._fix_indent(*m.groups())),
251251
inspect.cleandoc('\n' + body)
252252
)
253+
elif section in ('Returns', 'Yields', 'Raises', 'Warns'):
254+
body = re.compile(
255+
r'^()([\w.,\[\] ]+): '
256+
r'((?:.*)(?:\n(?: {2,}.*|$))*)', re.MULTILINE).sub(
257+
lambda m: _ToMarkdown._deflist(*_ToMarkdown._fix_indent(*m.groups())),
258+
inspect.cleandoc('\n' + body)
259+
)
253260
return '\n{}\n-----\n{}'.format(section, body)
254261

255262
text = re.compile(r'^([A-Z]\w+):$\n'

pdoc/test/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,20 +1172,25 @@ def test_google(self):
11721172
</dl>
11731173
<h2 id="returns">Returns</h2>
11741174
<dl>
1175-
<dt><strong><code>issue_10</code></strong></dt>
1175+
<dt><code>issue_10</code></dt>
11761176
<dd>description didn't work across multiple lines
11771177
if only a single item was listed. <code><a>inspect.cleandoc()</a></code>
11781178
somehow stripped the required extra indentation.</dd>
11791179
</dl>
1180+
<h2 id="returns_1">Returns</h2>
1181+
<dl>
1182+
<dt><code>Dict[int, <a>pdoc.Doc</a>]</code></dt>
1183+
<dd>Description.</dd>
1184+
</dl>
11801185
<h2 id="raises">Raises</h2>
11811186
<dl>
1182-
<dt><strong><code>AttributeError</code></strong></dt>
1187+
<dt><code>AttributeError</code></dt>
11831188
<dd>
11841189
<p>The <code>Raises</code> section is a list of all exceptions
11851190
that are relevant to the interface.</p>
11861191
<p>and a third line.</p>
11871192
</dd>
1188-
<dt><strong><code>ValueError</code></strong></dt>
1193+
<dt><code>ValueError</code></dt>
11891194
<dd>If <code>arg2</code> is equal to <code>arg1</code>.</dd>
11901195
</dl>
11911196
<p>Test a title without a blank line before it.</p>

pdoc/test/example_pkg/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ def google(self):
230230
if only a single item was listed. `inspect.cleandoc()`
231231
somehow stripped the required extra indentation.
232232
233+
Returns:
234+
Dict[int, pdoc.Doc]: Description.
235+
233236
Raises:
234237
AttributeError: The ``Raises`` section is a list of all exceptions
235238
that are relevant to the interface.

0 commit comments

Comments
 (0)