@@ -341,7 +341,7 @@ def scan(self):
341
341
modsrc = self .get_blocksrc (block )
342
342
343
343
# Get module description
344
- block ['desc' ] = self .get_comment (modsrc , aslist = True )
344
+ block ['desc' ], block [ 'synopsis' ] = self .get_comment (modsrc , aslist = True )
345
345
346
346
# Scan types and routines
347
347
for subblock in block ['body' ]:
@@ -392,7 +392,7 @@ def scan_container(self, block, insrc=None):
392
392
subsrc = self .get_blocksrc (block , insrc )
393
393
394
394
# Comment
395
- block ['desc' ] = self .get_comment (subsrc , aslist = True )
395
+ block ['desc' ], block [ 'synopsis' ] = self .get_comment (subsrc , aslist = True )
396
396
397
397
# Scan comments to find descriptions
398
398
if block ['desc' ] and block ['block' ] in [
@@ -671,6 +671,7 @@ def get_comment(
671
671
- OR ``scomment,ilast``: if ``getilast is True``
672
672
"""
673
673
scomment = []
674
+ synopsis = []
674
675
if src :
675
676
in_a_breaked_line = src [0 ].strip ().endswith ('&' )
676
677
for iline in range (iline , len (src )):
@@ -713,15 +714,18 @@ def get_comment(
713
714
prefix = self ._re_space_prefix_match (comment ).group (1 )
714
715
if comment .startswith (prefix ):
715
716
comment = comment [len (prefix ):]
716
-
717
- # Save comment
718
- scomment .append (comment )
717
+ # Is it the synopsis?
718
+ if comment .lstrip ().startswith (':synopsis:' ):
719
+ synopsis .append (comment .replace (':synopsis:' ,'' ))
720
+ else :
721
+ scomment .append (comment )
719
722
720
723
if not aslist :
721
724
scomment = self .format_lines (scomment , nlc = ' ' )
725
+ synopsis = self .format_lines (synopsis , nlc = ' ' )
722
726
if getilast :
723
727
return scomment , iline
724
- return scomment
728
+ return scomment , synopsis
725
729
726
730
def get_synopsis (self , block , nmax = 3 ):
727
731
"""Get the first ``nmax`` non empty lines of the function, type or module comment as 1 line.
@@ -730,17 +734,22 @@ def get_synopsis(self, block, nmax=3):
730
734
If description if empty, it returns an empty string.
731
735
"""
732
736
sd = []
733
- for line in block ['desc' ]:
734
- line = line .strip ()
735
- if not line :
736
- if not sd :
737
- continue
738
- break
739
- sd .append (line )
740
- if len (sd ) > nmax :
741
- if sd [- 1 ].endswith ('.' ):
742
- sd [- 1 ] += '..'
743
- break
737
+ if block ['synopsis' ]:
738
+ for line in block ['synopsis' ]:
739
+ line = line .strip ()
740
+ sd .append (line )
741
+ else :
742
+ for line in block ['desc' ]:
743
+ line = line .strip ()
744
+ if not line :
745
+ if not sd :
746
+ continue
747
+ break
748
+ sd .append (line )
749
+ if len (sd ) > nmax :
750
+ if sd [- 1 ].endswith ('.' ):
751
+ sd [- 1 ] += '..'
752
+ break
744
753
if not sd :
745
754
return ''
746
755
sd = ' ' .join (sd )
@@ -1643,6 +1652,15 @@ def format_variables(self, block, indent=0, ownSection=False):
1643
1652
elif variables and ownSection : variables += '\n \n '
1644
1653
return variables
1645
1654
1655
+ def format_synopsis (self , block , indent = 0 ):
1656
+ """Format the description of an object"""
1657
+ synopsis = ''
1658
+ if block ['synopsis' ]:
1659
+ synopsis = self .format_subsection ('Synopsis' , indent = indent )
1660
+ synopsis += self .format_lines (
1661
+ block ['synopsis' ], indent = indent , strip = True ) + '\n '
1662
+ return synopsis
1663
+
1646
1664
def format_description (self , block , indent = 0 ):
1647
1665
"""Format the description of an object"""
1648
1666
description = ''
@@ -1682,6 +1700,9 @@ def format_module(self, block, indent=0):
1682
1700
'module' , modname , indent = indent , options = dict (
1683
1701
synopsis = self .get_synopsis (block ).strip () or None ))
1684
1702
1703
+ # Description
1704
+ synopsis = self .format_synopsis (block , indent = indent )
1705
+
1685
1706
# Description
1686
1707
description = self .format_description (block , indent = indent )
1687
1708
@@ -1703,7 +1724,7 @@ def format_module(self, block, indent=0):
1703
1724
if self .hide_output :
1704
1725
return declaration
1705
1726
else :
1706
- return declaration + description + quickaccess + \
1727
+ return declaration + synopsis + description + quickaccess + \
1707
1728
use + types + variables + routines
1708
1729
1709
1730
def format_srcfile (
0 commit comments