import re


def collect_all_links(section_with_all_links,
                      regex_skip_sections_start,
                      regex_skip_sections_end):
    """
    Goes through a section and extract all inlined links it can found.

    :param section_with_all_links: An array of lines representing a section. For this function to work, all links must be inlined first.
    :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 all_links: An array of all unique links that where found within a section.
    """
    regex_link_inlined = r"\[.*?\]\((?![#?])(\S*?)\)"
    all_links = []
    skip = False
    for line in section_with_all_links:
        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:
                line_links = re.findall(regex_link_inlined, line,
                                        re.MULTILINE)
                if not line_links == []:
                    for link in line_links:

                        # If the link is already in the array, then it doesn't add it to avoid duplicated link

                        if link not in all_links:
                            all_links.append(link)

    # 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 all_links