sphinx_nbexamples/__init__.py
def get_description(self):
        """Get summary and description of this notebook"""
        def split_header(s, get_header=True):
            s = s.lstrip().rstrip()
            parts = s.splitlines()
            if parts[0].startswith('#'):
                if get_header:
                    header = re.sub('#+\s*', '', parts.pop(0))
                    if not parts:
                        return header, ''
                else:
                    header = ''
                rest = '\n'.join(parts).lstrip().split('\n\n')
                desc = rest[0].replace('\n', ' ')
                return header, desc
            else:
                if get_header:
                    if parts[0].startswith(('=', '-')):
                        parts = parts[1:]
                    header = parts.pop(0)
                    if parts and parts[0].startswith(('=', '-')):
                        parts.pop(0)
                    if not parts:
                        return header, ''
                else:
                    header = ''
                rest = '\n'.join(parts).lstrip().split('\n\n')
                desc = rest[0].replace('\n', ' ')
                return header, desc

        first_cell = self.nb['cells'][0]

        if not first_cell['cell_type'] == 'markdown':
            return '', ''
        header, desc = split_header(first_cell['source'])
        if not desc and len(self.nb['cells']) > 1:
            second_cell = self.nb['cells'][1]
            if second_cell['cell_type'] == 'markdown':
                _, desc = split_header(second_cell['source'], False)
        return header, desc
def get_description(self):
        """Get summary and description of this notebook"""
        def split_header(s, get_header=True):
            s = s.lstrip().rstrip()
            parts = s.splitlines()
            if parts[0].startswith('#'):
                if get_header:
                    header = re.sub('#+\s*', '', parts.pop(0))
                    if not parts:
                        return header, ''
                else:
                    header = ''
                rest = '\n'.join(parts).lstrip().split('\n\n')
                desc = rest[0].replace('\n', ' ')
                return header, desc
            else:
                if get_header:
                    if parts[0].startswith(('=', '-')):
                        parts = parts[1:]
                    header = parts.pop(0)
                    if parts and parts[0].startswith(('=', '-')):
                        parts.pop(0)
                    if not parts:
                        return header, ''
                else:
                    header = ''
                rest = '\n'.join(parts).lstrip().split('\n\n')
                desc = rest[0].replace('\n', ' ')
                return header, desc

        first_cell = self.nb['cells'][0]

        if not first_cell['cell_type'] == 'markdown':
            return '', ''
        header, desc = split_header(first_cell['source'])
        if not desc and len(self.nb['cells']) > 1:
            second_cell = self.nb['cells'][1]
            if second_cell['cell_type'] == 'markdown':
                _, desc = split_header(second_cell['source'], False)
        return header, desc
def get_description ( self ) : def split_header ( s , get_header = True ) : s = s . lstrip ( ) . rstrip ( ) parts = s . splitlines ( ) if parts [ 0 ] . startswith ( '#' ) : if get_header : header = re . sub ( '#+\s*' , '' , parts . pop ( 0 ) ) if not parts : return header , '' else : header = '' rest = '\n' . join ( parts ) . lstrip ( ) . split ( '\n\n' ) desc = rest [ 0 ] . replace ( '\n' , ' ' ) return header , desc else : if get_header : if parts [ 0 ] . startswith ( ( '=' , '-' ) ) : parts = parts [ 1 : ] header = parts . pop ( 0 ) if parts and parts [ 0 ] . startswith ( ( '=' , '-' ) ) : parts . pop ( 0 ) if not parts : return header , '' else : header = '' rest = '\n' . join ( parts ) . lstrip ( ) . split ( '\n\n' ) desc = rest [ 0 ] . replace ( '\n' , ' ' ) return header , desc first_cell = self . nb [ 'cells' ] [ 0 ] if not first_cell [ 'cell_type' ] == 'markdown' : return '' , '' header , desc = split_header ( first_cell [ 'source' ] ) if not desc and len ( self . nb [ 'cells' ] ) > 1 : second_cell = self . nb [ 'cells' ] [ 1 ] if second_cell [ 'cell_type' ] == 'markdown' : _ , desc = split_header ( second_cell [ 'source' ] , False ) return header , desc
Get summary and description of this notebook
Get summary and description of this notebook