Source code for distro_tracker.core.utils.linkify

# Copyright 2014 The Distro Tracker Developers
# See the COPYRIGHT file at the top-level directory of this distribution and
# at https://deb.li/DTAuthors
#
# This file is part of Distro Tracker. It is subject to the license terms
# in the LICENSE file found in the top-level directory of this
# distribution and at https://deb.li/DTLicense. No part of Distro Tracker,
# including this file, may be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.

"""
Module including some utility functions to inject links in plain text.
"""
import re

from django.conf import settings

from distro_tracker.core.utils.plugins import PluginRegistry


[docs]class Linkify(metaclass=PluginRegistry): """ A base class representing ways to inject useful links in plain text data If you want to recognize a new syntax where links could provide value to a view of the content, just create a subclass and implement the linkify method. """
[docs] @staticmethod def linkify(text): """ :param text: the text where we should inject HTML links :type param: str :returns: the text formatted with HTML links :rtype: str """ return text
[docs]def linkify(message): """ :param message: the message where we should inject HTML links :type param: str :returns: the message formatted with HTML links :rtype: str """ for plugin in Linkify.plugins: message = plugin.linkify(message) return message