Takes cleaned text and creates HTML-formatted, web-friendly version.
    - converts links to images and video to actual media objects.
    - Make raw links clickable (and truncated, if necessary).
    - Converts smilies and markdown to valid HTML.
    _ Bleaches output (again) to catch any stray HTML inserted by markdown.

    ALWAYS PASS CLEANED TEXT.

def format_text(value):
    """
    Takes cleaned text and creates HTML-formatted, web-friendly version.
    - converts links to images and video to actual media objects.
    - Make raw links clickable (and truncated, if necessary).
    - Converts smilies and markdown to valid HTML.
    _ Bleaches output (again) to catch any stray HTML inserted by markdown.

    ALWAYS PASS CLEANED TEXT.

    """
    # convert media links
    value = convert_links(value)
    value = urlizetrunc(value, 30)

    for x in EMOTICON_REPLACEMENTS:
        value = value.replace(x[0], '<span class="emoticon-{}"></span>'.format(x[1]))

    markedup = markdown.markdown(value).replace('</p>\n<p>', '</p><p>')
    with_linebreaks = markedup.replace('\n* ', '<br>* ')
    bleached = bleach.clean(with_linebreaks, tags=ALLOWED_TAGS, attributes=ALLOWED_ATTRIBUTES, strip=True)
    return mark_safe(bleached)