wikitextparser/_wikitext.py
def sections(self) -> List['Section']:
        """Return a list of section in current wikitext.

        The first section will always be the lead section, even if it is an
        empty string.
        """
        sections = []  # type: List['Section']
        sections_append = sections.append
        type_to_spans = self._type_to_spans
        lststr = self._lststr
        ss, se = _span = self._span
        type_spans = type_to_spans.setdefault('Section', [])
        full_match = SECTIONS_FULLMATCH(self._shadow)
        section_spans = full_match.spans('section')
        levels = [len(eq) for eq in full_match.captures('equals')]
        if not type_spans:
            # All spans are new
            spans_append = type_spans.append
            for current_index, (current_level, (s, e)) in enumerate(
                zip(levels, section_spans), 1
            ):
                # Add text of the current_section to any parent section.
                # Note that section 0 is not a parent for any subsection.
                for section_index, section_level in enumerate(
                    levels[current_index:], current_index
                ):
                    if current_level and section_level > current_level:
                        e = section_spans[section_index][1]
                    else:
                        break
                span = [ss + s, ss + e]
                spans_append(span)
                sections_append(
                    Section(lststr, type_to_spans, span, 'Section'))
            return sections
        # There are already some spans. Instead of appending new spans
        # use them when the detected span already exists.
        span_tuple_to_span = {(s[0], s[1]): s for s in type_spans}.get
        for current_index, (current_level, (s, e)) in enumerate(
            zip(levels, section_spans), 1
        ):
            # Add text of the current_section to any parent section.
            # Note that section 0 is not a parent for any subsection.
            for section_index, section_level in enumerate(
                levels[current_index:], current_index
            ):
                if current_level and section_level > current_level:
                    e = section_spans[section_index][1]
                else:
                    break
            s, e = ss + s, ss + e
            old_span = span_tuple_to_span((s, e))
            if old_span is None:
                span = [s, e]
                insort(type_spans, span)
            else:
                span = old_span
            sections_append(Section(lststr, type_to_spans, span, 'Section'))
        return sections
def sections(self) -> List['Section']:
        """Return a list of section in current wikitext.

        The first section will always be the lead section, even if it is an
        empty string.
        """
        sections = []  # type: List['Section']
        sections_append = sections.append
        type_to_spans = self._type_to_spans
        lststr = self._lststr
        ss, se = _span = self._span
        type_spans = type_to_spans.setdefault('Section', [])
        full_match = SECTIONS_FULLMATCH(self._shadow)
        section_spans = full_match.spans('section')
        levels = [len(eq) for eq in full_match.captures('equals')]
        if not type_spans:
            # All spans are new
            spans_append = type_spans.append
            for current_index, (current_level, (s, e)) in enumerate(
                zip(levels, section_spans), 1
            ):
                # Add text of the current_section to any parent section.
                # Note that section 0 is not a parent for any subsection.
                for section_index, section_level in enumerate(
                    levels[current_index:], current_index
                ):
                    if current_level and section_level > current_level:
                        e = section_spans[section_index][1]
                    else:
                        break
                span = [ss + s, ss + e]
                spans_append(span)
                sections_append(
                    Section(lststr, type_to_spans, span, 'Section'))
            return sections
        # There are already some spans. Instead of appending new spans
        # use them when the detected span already exists.
        span_tuple_to_span = {(s[0], s[1]): s for s in type_spans}.get
        for current_index, (current_level, (s, e)) in enumerate(
            zip(levels, section_spans), 1
        ):
            # Add text of the current_section to any parent section.
            # Note that section 0 is not a parent for any subsection.
            for section_index, section_level in enumerate(
                levels[current_index:], current_index
            ):
                if current_level and section_level > current_level:
                    e = section_spans[section_index][1]
                else:
                    break
            s, e = ss + s, ss + e
            old_span = span_tuple_to_span((s, e))
            if old_span is None:
                span = [s, e]
                insort(type_spans, span)
            else:
                span = old_span
            sections_append(Section(lststr, type_to_spans, span, 'Section'))
        return sections
Return a list of section in current wikitext.

        The first section will always be the lead section, even if it is an
        empty string.