Skip to content

Commit c5178bd

Browse files
authored
Merge pull request #107 from jnothman/deflist
Use definition lists rather than blockquotes
2 parents 2f075a6 + 0d9afc5 commit c5178bd

File tree

5 files changed

+123
-56
lines changed

5 files changed

+123
-56
lines changed

doc/install.rst

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ numpydoc_citation_re : str
3838
should be mangled to avoid conflicts due to
3939
duplication across the documentation. Defaults
4040
to ``[\w-]+``.
41+
numpydoc_use_blockqutoes : bool
42+
Until version 0.8, parameter definitions were shown as blockquotes, rather
43+
than in a definition list. If your styling requires blockquotes, switch
44+
this config option to True. This option will be removed in version 0.10.
4145
numpydoc_edit_link : bool
4246
.. deprecated:: edit your HTML template instead
4347

numpydoc/docscrape.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
import sys
1414

1515

16+
def strip_blank_lines(l):
17+
"Remove leading and trailing blank lines from a list of lines"
18+
while l and not l[0].strip():
19+
del l[0]
20+
while l and not l[-1].strip():
21+
del l[-1]
22+
return l
23+
24+
1625
class Reader(object):
1726
"""A line-based string reader.
1827
@@ -214,6 +223,7 @@ def _parse_param_list(self, content):
214223

215224
desc = r.read_to_next_unindented_line()
216225
desc = dedent_lines(desc)
226+
desc = strip_blank_lines(desc)
217227

218228
params.append((arg_name, arg_type, desc))
219229

@@ -404,7 +414,8 @@ def _str_param_list(self, name):
404414
out += ['%s : %s' % (param, param_type)]
405415
else:
406416
out += [param]
407-
out += self._str_indent(desc)
417+
if desc and ''.join(desc).strip():
418+
out += self._str_indent(desc)
408419
out += ['']
409420
return out
410421

numpydoc/docscrape_sphinx.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def __init__(self, docstring, config={}):
3131

3232
def load_config(self, config):
3333
self.use_plots = config.get('use_plots', False)
34+
self.use_blockquotes = config.get('use_blockquotes', False)
3435
self.class_members_toctree = config.get('class_members_toctree', True)
3536
self.template = config.get('template', None)
3637
if self.template is None:
@@ -66,18 +67,26 @@ def _str_extended_summary(self):
6667
return self['Extended Summary'] + ['']
6768

6869
def _str_returns(self, name='Returns'):
70+
if self.use_blockquotes:
71+
typed_fmt = '**%s** : %s'
72+
untyped_fmt = '**%s**'
73+
else:
74+
typed_fmt = '%s : %s'
75+
untyped_fmt = '%s'
76+
6977
out = []
7078
if self[name]:
7179
out += self._str_field_list(name)
7280
out += ['']
7381
for param, param_type, desc in self[name]:
7482
if param_type:
75-
out += self._str_indent(['**%s** : %s' % (param.strip(),
76-
param_type)])
83+
out += self._str_indent([typed_fmt % (param.strip(),
84+
param_type)])
7785
else:
78-
out += self._str_indent([param.strip()])
86+
out += self._str_indent([untyped_fmt % param.strip()])
7987
if desc:
80-
out += ['']
88+
if self.use_blockquotes:
89+
out += ['']
8190
out += self._str_indent(desc, 8)
8291
out += ['']
8392
return out
@@ -117,7 +126,7 @@ def _process_param(self, param, desc, fake_autosummary):
117126
relies on Sphinx's plugin mechanism.
118127
"""
119128
param = param.strip()
120-
display_param = '**%s**' % param
129+
display_param = ('**%s**' if self.use_blockquotes else '%s') % param
121130

122131
if not fake_autosummary:
123132
return display_param, desc
@@ -192,7 +201,8 @@ def _str_param_list(self, name, fake_autosummary=False):
192201
else:
193202
out += self._str_indent([display_param])
194203
if desc:
195-
out += [''] # produces a blockquote, rather than a dt/dd
204+
if self.use_blockquotes:
205+
out += ['']
196206
out += self._str_indent(desc, 8)
197207
out += ['']
198208

@@ -262,7 +272,6 @@ def _str_section(self, name):
262272
out = []
263273
if self[name]:
264274
out += self._str_header(name)
265-
out += ['']
266275
content = textwrap.dedent("\n".join(self[name])).split("\n")
267276
out += content
268277
out += ['']
@@ -281,6 +290,7 @@ def _str_warnings(self):
281290
if self['Warnings']:
282291
out = ['.. warning::', '']
283292
out += self._str_indent(self['Warnings'])
293+
out += ['']
284294
return out
285295

286296
def _str_index(self):
@@ -297,6 +307,7 @@ def _str_index(self):
297307
out += [' single: %s' % (', '.join(references))]
298308
else:
299309
out += [' %s: %s' % (section, ','.join(references))]
310+
out += ['']
300311
return out
301312

302313
def _str_references(self):

numpydoc/numpydoc.py

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def mangle_docstrings(app, what, name, obj, options, lines):
7171
return
7272

7373
cfg = {'use_plots': app.config.numpydoc_use_plots,
74+
'use_blockquotes': app.config.numpydoc_use_blockquotes,
7475
'show_class_members': app.config.numpydoc_show_class_members,
7576
'show_inherited_class_members':
7677
app.config.numpydoc_show_inherited_class_members,
@@ -139,6 +140,7 @@ def setup(app, get_doc_object_=get_doc_object):
139140
app.connect('autodoc-process-signature', mangle_signature)
140141
app.add_config_value('numpydoc_edit_link', None, False)
141142
app.add_config_value('numpydoc_use_plots', None, False)
143+
app.add_config_value('numpydoc_use_blockquotes', None, False)
142144
app.add_config_value('numpydoc_show_class_members', True, True)
143145
app.add_config_value('numpydoc_show_inherited_class_members', True, True)
144146
app.add_config_value('numpydoc_class_members_toctree', True, True)

0 commit comments

Comments
 (0)