Skip to main content

Link recognition for Python Markdown

Project description

Mdx Linkify

Travis Coveralls PyPI PyPI

This extension for Python Markdown will convert text that look like links to HTML anchors.

There's an alternative package that serves the same purpose called markdown-urlize. The main difference is that mdx_linkify is utilizing the excellent bleach for searching links in text. :clap:


Minimal Example

from markdown import markdown

markdown("minimal", extensions=["mdx_linkify"])
# Returns '<p>minimal <a href=""></a></p>'


The project is on PyPI!

pip install mdx_linkify

If you want the bleeding-edge version (this includes unreleased-to-PyPI code), you can always grab the master branch directly from Git.

pip install git+git://

Configuring Linker

To configure used Linker instance, use linker_options parameter. It will be passed to bleach.linkifier.Linker unchanged.

Example: Parse Emails

from mdx_linkify.mdx_linkify import LinkifyExtension
from markdown import Markdown

md = Markdown(
    extensions=[LinkifyExtension(linker_options={"parse_email": True})],

assert md.convert(''), '<p><a href=""></a></p>'

Example: Custom TLDs

from mdx_linkify.mdx_linkify import LinkifyExtension
from bleach.linkifier import build_url_re
from markdown import Markdown

md = Markdown(
    extensions=[LinkifyExtension(linker_options={"url_re": build_url_re(["custom", "custom2"])})],

assert md.convert('linked.custom'), '<p><a href="http://linked.custom">linked.custom</a></p>'

Example: Ignoring TLDs

from mdx_linkify.mdx_linkify import LinkifyExtension
from markdown import Markdown

def dont_linkify_net_tld(attrs, new=False):
    if attrs["_text"].endswith(".net"):
        return None

    return attrs

md = Markdown(
    extensions=[LinkifyExtension(linker_options={"callbacks": [dont_linkify_net_tld]})],

assert md.convert(""), '<p></p>'


git clone
virtualenv mdx_linkify/
cd mdx_linkify/
source bin/activate
python install
python test

Pull requests are much welcome! :+1:


(more like a cheatsheet for me actually)

  • Change version in,
  • Commit and tag it,
  • Push it (including tag),
  • Run python register && python sdist upload;

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mdx_linkify-2.1.tar.gz (4.3 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page