Skip to content

Commit ab5ec54

Browse files
authored
Merge pull request #57 from arewm/noepilog
add directive to ignore epilog when parsing
2 parents 1a04f2f + e881b10 commit ab5ec54

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

sphinxarg/ext.py

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class ArgParseDirective(Directive):
235235
prog=unchanged, path=unchanged, nodefault=flag,
236236
nodefaultconst=flag, filename=unchanged,
237237
manpage=unchanged, nosubcommands=unchanged, passparser=flag,
238+
noepilog=unchanged, nodescription=unchanged,
238239
markdown=flag, markdownhelp=flag)
239240

240241
def _construct_manpage_specific_structure(self, parser_info):
@@ -248,29 +249,38 @@ def _construct_manpage_specific_structure(self, parser_info):
248249
SEE ALSO
249250
BUGS
250251
"""
252+
items = []
251253
# SYNOPSIS section
252254
synopsis_section = nodes.section(
253255
'',
254256
nodes.title(text='Synopsis'),
255257
nodes.literal_block(text=parser_info["bare_usage"]),
256258
ids=['synopsis-section'])
259+
items.append(synopsis_section)
257260
# DESCRIPTION section
258-
description_section = nodes.section(
259-
'',
260-
nodes.title(text='Description'),
261-
nodes.paragraph(text=parser_info.get(
262-
'description', parser_info.get(
263-
'help', "undocumented").capitalize())),
264-
ids=['description-section'])
265-
nested_parse_with_titles(
266-
self.state, self.content, description_section)
267-
if parser_info.get('epilog'):
261+
if 'nodescription' not in self.options:
262+
description_section = nodes.section(
263+
'',
264+
nodes.title(text='Description'),
265+
nodes.paragraph(text=parser_info.get(
266+
'description', parser_info.get(
267+
'help', "undocumented").capitalize())),
268+
ids=['description-section'])
269+
nested_parse_with_titles(
270+
self.state, self.content, description_section)
271+
items.append(description_section)
272+
if parser_info.get('epilog') and 'noepilog' not in self.options:
268273
# TODO: do whatever sphinx does to understand ReST inside
269274
# docstrings magically imported from other places. The nested
270275
# parse method invoked above seem to be able to do this but
271276
# I haven't found a way to do it for arbitrary text
272-
description_section += nodes.paragraph(
273-
text=parser_info['epilog'])
277+
if description_section:
278+
description_section += nodes.paragraph(
279+
text=parser_info['epilog'])
280+
else:
281+
description_section = nodes.paragraph(
282+
text=parser_info['epilog'])
283+
items.append(description_section)
274284
# OPTIONS section
275285
options_section = nodes.section(
276286
'',
@@ -285,15 +295,13 @@ def _construct_manpage_specific_structure(self, parser_info):
285295
options_section += nodes.paragraph()
286296
options_section += nodes.subtitle(text=action_group['title'])
287297
options_section += self._format_optional_arguments(action_group)
288-
items = [
289-
# NOTE: we cannot generate NAME ourselves. It is generated by
290-
# docutils.writers.manpage
291-
synopsis_section,
292-
description_section,
293-
# TODO: files
294-
# TODO: see also
295-
# TODO: bugs
296-
]
298+
299+
# NOTE: we cannot generate NAME ourselves. It is generated by
300+
# docutils.writers.manpage
301+
# TODO: items.append(files)
302+
# TODO: items.append(see also)
303+
# TODO: items.append(bugs)
304+
297305
if len(options_section.children) > 1:
298306
items.append(options_section)
299307
if 'nosubcommands' not in self.options:
@@ -462,15 +470,15 @@ def run(self):
462470
markDownHelp = False
463471
if 'markdownhelp' in self.options:
464472
markDownHelp = True
465-
if 'description' in result:
473+
if 'description' in result and 'nodescription' not in self.options:
466474
if markDownHelp:
467475
items.extend(renderList([result['description']], True))
468476
else:
469477
items.append(self._nested_parse_paragraph(result['description']))
470478
items.append(nodes.literal_block(text=result['usage']))
471479
items.extend(print_action_groups(result, nested_content, markDownHelp))
472480
items.extend(print_subcommands(result, nested_content, markDownHelp))
473-
if 'epilog' in result:
481+
if 'epilog' in result and 'noepilog' not in self.options:
474482
items.append(self._nested_parse_paragraph(result['epilog']))
475483

476484
# Traverse the returned nodes, modifying the title IDs as necessary to avoid repeats

0 commit comments

Comments
 (0)