Link recognition for Python Markdown
Project description
Mdx Linkify
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:
Usage
Minimal Example
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>'
Installation
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://github.com/daGrevis/mdx_linkify.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('contact@example.com'), '<p><a href="mailto:contact@example.com">contact@example.com</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("not-linked.net"), '<p>not-linked.net</p>'
Development
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! :+1:
Releasing
(more like a cheatsheet for me actually)
- Change version in
setup.py
, - Commit and tag it,
- Push it (including tag),
- Run
python setup.py register && python setup.py 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
Built Distributions
File details
Details for the file mdx_linkify-2.0.tar.gz
.
File metadata
- Download URL: mdx_linkify-2.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a460e9febd16e70cdc90d58856e43ecffbd26233d1ded9ed38c7c9f4a1b4b1f |
|
MD5 | b86c31aa44d79bcb49315e187bc0b2b0 |
|
BLAKE2b-256 | 5145e24a304a248af4e2df201f5f45be0924b40555d2551e9db1a524e06b4304 |
File details
Details for the file mdx_linkify-2.0-py3.8.egg
.
File metadata
- Download URL: mdx_linkify-2.0-py3.8.egg
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ab0d14efc01029005b9e8f77efd9a18b7d09a044e121af1fbfc6628ae08259f |
|
MD5 | 03c669c53b50373925393b822ad08812 |
|
BLAKE2b-256 | dacd5ced2f4031b4493e18b6948572970ecf9ee0868bcdadffab207139c3a747 |
File details
Details for the file mdx_linkify-2.0-py3-none-any.whl
.
File metadata
- Download URL: mdx_linkify-2.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4e73c26741404e0762f0ed50ef830981fb8dc60150ec961e701c993175fbba3 |
|
MD5 | d48eef5aa610554f1446e0df94abc31c |
|
BLAKE2b-256 | 167c8a8d4309ce537bb0d2373c470750537bf068302f5071601f06f91e6b66d3 |