def get_examples()

in find_examples_manpage_data.py [0:0]


def get_examples(command):
    name = command['name']
    examples = []

    regex_name = re.compile(fr"\b{re.escape(name)}\b")

    for p in command['paragraphs']:
        text = p['text'].strip()
        parser = HTMLTextParser()
        parser.feed(text)
        p['text'] = "".join(parser.data)

    query = ""

    for i, p in enumerate(command['paragraphs']):
        if p['section'] is None:
            continue
        section = p['section'].lower()
        if not "example" in section:
            continue
        example = p['text']

        found = False
        if example.startswith(name):
            found = True
        if not found and example.startswith("$ "):
            example = example[2:]
            found = True
        if not found:
            for match in regex_name.finditer(example):
                if match.start(0) > 10:
                    query = example[:match.start(0)].strip()
                example = example[match.start(0):]

                found = True
                break

        if not found:
            continue

        example = re.sub(r"\\\s+", "", example)
        if example.find('\n') != -1:
            last_index = example.find('\n')
            if check_query(example[last_index:].strip()):
                query = example[last_index:].strip()
            example = example[:last_index].strip()

        if i > 0:
            line = command['paragraphs'][i - 1]['text']
            if line.endswith(":"):
                query = line[:-1]
        if not query and i + 1 < len(command['paragraphs']):
            line = command['paragraphs'][i + 1]['text']
            if check_query(line):
                query = line
        examples.append([name, example, query])
        query = ""
    return examples