https://github.com/daGrevis/mdx_linkify
Link recognition for Python Markdown
https://github.com/daGrevis/mdx_linkify
extension linkify markdown python urlify
Last synced: about 1 year ago
JSON representation
Link recognition for Python Markdown
- Host: GitHub
- URL: https://github.com/daGrevis/mdx_linkify
- Owner: daGrevis
- License: mit
- Created: 2013-02-16T18:32:03.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2021-03-10T09:26:45.000Z (over 5 years ago)
- Last Synced: 2024-07-25T04:34:37.483Z (almost 2 years ago)
- Topics: extension, linkify, markdown, python, urlify
- Language: Python
- Size: 60.5 KB
- Stars: 24
- Watchers: 3
- Forks: 12
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mdx Linkify
[](https://travis-ci.org/daGrevis/mdx_linkify)
[](https://coveralls.io/r/daGrevis/mdx_linkify?branch=master)
[](https://pypi.python.org/pypi/mdx_linkify)
[](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 '
minimal http://example.org/
'
```
## 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
### Configuring Linker
To configure used Linker instance, use `linker_options` parameter. It will be passed to [`bleach.linkifier.Linker`](https://bleach.readthedocs.io/en/latest/linkify.html#using-bleach-linkifier-linker) unchanged.
#### Example: Parse Emails
```python
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') == '
'
```
#### Example: Custom TLDs
```python
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') == '
'
```
#### Example: Ignoring TLDs
```python
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") == '
not-linked.net
'
```
## 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`;