Source code for indieweb_utils.utils.autotag

import re
from typing import List


def _match_tag(tag_prefix: str, match: str, user_tags: List[str]) -> str:
    """
    Match a tag and return a link to the tag page.

    :param tag_prefix: The prefix to append to the tag.
    :type tag_prefix: str
    :param match: The match to process.
    :type match: str
    :param user_tags: A list of tags that a user supports on their website.
    :type user_tags: List[str]
    :return: The processed match.
    :rtype: str
    """
    tag = match[1:]
    if len(user_tags) > 0 and tag in user_tags:
        return f"<a href='{tag_prefix}{tag}'>#{tag}</a>"
    else:
        return match


def _match_person_tag(people: dict, match: str) -> str:
    """
    A person tag and return a link to their profile.

    :param people: A dictionary of names to which a person tag can be matched.
    :type people: dict
    :param match: The match to process.
    :type match: str
    :return: The processed match.
    :rtype: str
    """
    person = match[1:]
    if people.get(person):
        return f"<a href='{people[person][1]}'>{people[person][0]}</a>"
    else:
        return match