Link recognition for Python Markdown
Project description
# Mdx Linkify
[![Build Status](https://travis-ci.org/daGrevis/mdx_linkify.png?branch=master)](https://travis-ci.org/daGrevis/mdx_linkify) [![Coverage Status](https://coveralls.io/repos/daGrevis/mdx_linkify/badge.png?branch=master)](https://coveralls.io/r/daGrevis/mdx_linkify?branch=master)
This extension for [Python Markdown](https://github.com/waylan/Python-Markdown) will convert all links to HTML anchors.
There’s [an existing solution](https://github.com/r0wb0t/markdown-urlize) for parsing links with regexes. Mdx Linkify is a bit smarter and asks [Bleach](https://github.com/jsocol/bleach) to parse them. :clap:
## An Example
### Basic Usage
>>> from markdown import markdown >>> text = "http://example.org/" >>> markdown(text) u'<p>http://example.org/</p>' >>> markdown(text, extensions=["linkify"]) u'<p><a href="http://example.org/">http://example.org/</a></p>'
### Linkify Callbacks
>>> from markdown import Markdown >>> text = "http://example.org/" >>> def dont_linkify_py_tld(attrs, new=False): >>> if not new: # This is an existing <a> tag, leave it be. >>> return attrs >>> >>> # If the TLD is '.py', make sure it starts with http: or https: >>> text = attrs['_text'] >>> if (text.endswith('.py') and >>> not text.startswith(('www.', 'http:', 'https:'))): >>> # This looks like a Python file, not a URL. Don't make a link. >>> return None >>> >>> # Everything checks out, keep going to the next callback. >>> return attrs >>> configs = { >>> 'linkify_callbacks': [[dont_linkify_py_tld], ''] >>> } >>> linkify_extension = LinkifyExtension(configs=configs) >>> md = Markdown(extensions=[linkify_extension]) >>> md.convert("https://setup.py") u'<p><a href="https://setup.py">https://setup.py</a></p>' >>> md.convert("setup.py") u'<p>setup.py</p>'
## Installation
Simple installation on current environment:
pip install mdx_linkify
You can add it to requirements.txt too:
echo ‘mdx_linkify’ >> requirements.txt
## Development
Fork repo,
Clone repo,
Create virtualenv,
Execute python setup.py install,
Add some awesome feature,
Check tests with python setup.py test,
Check pep8,
Add commit and push to forked repo,
Ask for a merge request,
Stay awesome! :+1:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.