A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/daGrevis/mdx_linkify below:

daGrevis/mdx_linkify: Link recognition for Python Markdown

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. 👏

from markdown import markdown

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

The project is on PyPI!

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://github.com/daGrevis/mdx_linkify.git

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

from mdx_linkify.mdx_linkify import LinkifyExtension
from markdown import Markdown

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

assert md.convert('contact@example.com') == '<p><a href="mailto:contact@example.com">contact@example.com</a></p>'
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" rel="nofollow">linked.custom</a></p>'
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("not-linked.net") == '<p>not-linked.net</p>'
git clone git@github.com:daGrevis/mdx_linkify.git
virtualenv mdx_linkify/
cd mdx_linkify/
source bin/activate
python setup.py install
python setup.py test

Pull requests are much welcome! 👍

(more like a cheatsheet for me actually)


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4