Skip to main content

Link recognition for Python Markdown

Project description

# Mdx Linkify

[![Travis](https://img.shields.io/travis/daGrevis/mdx_linkify.svg)](https://travis-ci.org/daGrevis/mdx_linkify)
[![Coveralls](https://img.shields.io/coveralls/daGrevis/mdx_linkify.svg)](https://coveralls.io/r/daGrevis/mdx_linkify?branch=master)
[![PyPI](https://img.shields.io/pypi/v/mdx_linkify.svg)](https://pypi.python.org/pypi/mdx_linkify)
[![PyPI](https://img.shields.io/pypi/pyversions/mdx_linkify.svg)](https://pypi.python.org/pypi/mdx_linkify)

This extension for [Python Markdown](https://github.com/waylan/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`](https://github.com/r0wb0t/markdown-urlize). The main
difference is that [`mdx_linkify`](https://github.com/daGrevis/mdx_linkify) is
utilizing the excellent [`bleach`](https://github.com/jsocol/bleach) for
searching links in text. :clap:

## Usage

### Minimal Example

```python
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>'
```

### Linkify Callbacks

It's possible to omit links that match your custom filter with linkify
callbacks.

For example, to omit links that end with `.txt` extension:

```python
from mdx_linkify.mdx_linkify import LinkifyExtension
from markdown import Markdown

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

return attrs

md = Markdown(
extensions=[LinkifyExtension()],
extension_configs={
"linkify": {
"linkify_callbacks": [[dont_linkify_txt_extension], ""]
}
}
)

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

expected = md.convert("example.com")
actual = '<p><a href="http://example.com">example.com</a></p>'
assert expected == actual
```

## Installation

The project is [on PyPI](https://pypi.python.org/pypi/mdx_linkify)!

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

## 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

mdx_linkify-1.2.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file mdx_linkify-1.2.tar.gz.

File metadata

  • Download URL: mdx_linkify-1.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/2.7

File hashes

Hashes for mdx_linkify-1.2.tar.gz
Algorithm Hash digest
SHA256 e310a522d74076c259a12a5f27428ddadd5e692366a9b5aedb094a1d19513c0d
MD5 c8e1e4d8608f010bf237448b38fd5f5c
BLAKE2b-256 5c3c9fb072589cfd00b6f291f43cab458b94f2a6809d0ecaf4da88282d4dc155

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page