346
346
raise NotImplementedError("sorry, no detailed help yet for %r" % self.name())
348
348
# Extract the summary (purpose) and sections out from the text
349
purpose,sections = self._get_help_parts(doc)
349
purpose,sections,order = self._get_help_parts(doc)
351
351
# If a custom usage section was provided, use it
352
352
if sections.has_key('Usage'):
384
384
# Add the custom sections (e.g. Examples). Note that there's no need
385
385
# to indent these as they must be indented already in the source.
387
labels = sorted(sections.keys())
389
result += ':%s:\n%s\n\n' % (label,sections[label])
388
if sections.has_key(label):
389
result += ':%s:\n%s\n\n' % (label,sections[label])
391
391
# Add the aliases, source (plug-in) and see also links, if any
421
421
def _get_help_parts(text):
422
422
"""Split help text into a summary and named sections.
424
:return: (summary,sections) where summary is the top line and
424
:return: (summary,sections,order) where summary is the top line and
425
425
sections is a dictionary of the rest indexed by section name.
426
order is the order the section appear in the text.
426
427
A section starts with a heading line of the form ":xxx:".
427
428
Indented text on following lines is the section value.
428
429
All text found outside a named section is assigned to the
429
430
default section which is given the key of None.
431
def save_section(sections, label, section):
432
def save_section(sections, order, label, section):
432
433
if len(section) > 0:
433
434
if sections.has_key(label):
434
435
sections[label] += '\n' + section
436
438
sections[label] = section
438
440
lines = text.rstrip().splitlines()
439
441
summary = lines.pop(0)
441
444
label,section = None,''
442
445
for line in lines:
443
446
if line.startswith(':') and line.endswith(':') and len(line) > 2:
444
save_section(sections, label, section)
447
save_section(sections, order, label, section)
445
448
label,section = line[1:-1],''
446
449
elif (label is not None) and len(line) > 1 and not line[0].isspace():
447
save_section(sections, label, section)
450
save_section(sections, order, label, section)
448
451
label,section = None,line
450
453
if len(section) > 0:
451
454
section += '\n' + line
454
save_section(sections, label, section)
455
return summary, sections
457
save_section(sections, order, label, section)
458
return summary, sections, order
457
460
def get_help_topic(self):
458
461
"""Return the commands help topic - its name."""