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. 👏
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! 👍
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;
Metadata
Release files for mdx-linkify 2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mdx_linkify-2.1.tar.gz | 4.3 kB | Without provenance | Details |
Release files / mdx_linkify-2.1.tar.gz
| Download URL | mdx_linkify-2.1.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e09278e43e5076b63398238b069a361913779683183481e9206235667cd89f54
|
|
BLAKE2b-256 checksum How to use checksums |
039ad07599b2e3487d4fa6dca76ecf80ae3d51d135c107d7ead09509a88ecc1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0
|
Security for mdx-linkify 2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.