import re


def inlining_all_links(
        section_without_references,
        all_references,
        regex_skip_sections_start,
        regex_skip_sections_end):
    """
    Goes through a section with a list of references and inline all references.

    :param section_without_references: An array of lines representing a section, for this function to work, all reference should be removed previously from the section.
    :param regex_skip_sections_start: regex defining the start line that indicates a block of line that shouldn't be processed.
    :param regex_skip_sections_end: regex defining the end line that indicates a block of line that shouldn't be processed.
    :return section_with_all_links: A section (an array of lines) is returned without any references in it, just pure inlined links.
    """

    section_with_all_links = []
    skip = False

    for line in section_without_references:
        if skip:
            if re.search(regex_skip_sections_end, line):
                skip = False
        elif not skip:
            if re.search(regex_skip_sections_start, line):
                skip = True
            else:
                for reference in all_references:
                    reference_index, reference_val = reference

                    curent_link = '][' + reference_index + ']'

                    line = line.replace(
                        curent_link, '](' + reference_val + ')')

        section_with_all_links.append(line)

    # By the end of the for loop skip should always be false otherwise it means that a codeblock is not closed.
    if skip:
        raise ValueError

    return section_with_all_links