mdx-linkify


Namemdx-linkify JSON
Version 2.1 PyPI version JSON
download
home_pagehttps://github.com/daGrevis/mdx_linkify
SummaryLink recognition for Python Markdown
upload_time2020-11-09 16:42:30
maintainer
docs_urlNone
authorRaitis (daGrevis) Stengrevics
requires_python
licenseMIT
keywords markdown links
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # 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>'
```

## 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'), '<p><a href="mailto:contact@example.com">contact@example.com</a></p>'
```

#### 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'), '<p><a href="http://linked.custom">linked.custom</a></p>'
```

#### 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"), '<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`;
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/daGrevis/mdx_linkify",
    "name": "mdx-linkify",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "markdown links",
    "author": "Raitis (daGrevis) Stengrevics",
    "author_email": "dagrevis@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/03/9a/d07599b2e3487d4fa6dca76ecf80ae3d51d135c107d7ead09509a88ecc1d/mdx_linkify-2.1.tar.gz",
    "platform": "",
    "description": "# Mdx Linkify\n\n[![Travis](https://img.shields.io/travis/daGrevis/mdx_linkify.svg)](https://travis-ci.org/daGrevis/mdx_linkify)\n[![Coveralls](https://img.shields.io/coveralls/daGrevis/mdx_linkify.svg)](https://coveralls.io/r/daGrevis/mdx_linkify?branch=master)\n[![PyPI](https://img.shields.io/pypi/v/mdx_linkify.svg)](https://pypi.python.org/pypi/mdx_linkify)\n[![PyPI](https://img.shields.io/pypi/pyversions/mdx_linkify.svg)](https://pypi.python.org/pypi/mdx_linkify)\n\nThis extension for [Python Markdown](https://github.com/waylan/Python-Markdown)\nwill convert text that look like links to HTML anchors.\n\nThere's an alternative package that serves the same purpose called\n[`markdown-urlize`](https://github.com/r0wb0t/markdown-urlize). The main\ndifference is that [`mdx_linkify`](https://github.com/daGrevis/mdx_linkify) is\nutilizing the excellent [`bleach`](https://github.com/jsocol/bleach) for\nsearching links in text. :clap:\n\n## Usage\n\n### Minimal Example\n\n```python\nfrom markdown import markdown\n\nmarkdown(\"minimal http://example.org/\", extensions=[\"mdx_linkify\"])\n# Returns '<p>minimal <a href=\"http://example.org/\">http://example.org/</a></p>'\n```\n\n## Installation\n\nThe project is [on PyPI](https://pypi.python.org/pypi/mdx_linkify)!\n\n    pip install mdx_linkify\n\nIf you want the bleeding-edge version (this includes unreleased-to-PyPI code),\nyou can always grab the master branch directly from Git.\n\n    pip install git+git://github.com/daGrevis/mdx_linkify.git\n\n### Configuring Linker\n\nTo 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.\n\n\n#### Example: Parse Emails\n\n```python\nfrom mdx_linkify.mdx_linkify import LinkifyExtension\nfrom markdown import Markdown\n\nmd = Markdown(\n    extensions=[LinkifyExtension(linker_options={\"parse_email\": True})],\n)\n\nassert md.convert('contact@example.com'), '<p><a href=\"mailto:contact@example.com\">contact@example.com</a></p>'\n```\n\n#### Example: Custom TLDs\n\n```python\nfrom mdx_linkify.mdx_linkify import LinkifyExtension\nfrom bleach.linkifier import build_url_re\nfrom markdown import Markdown\n\nmd = Markdown(\n    extensions=[LinkifyExtension(linker_options={\"url_re\": build_url_re([\"custom\", \"custom2\"])})],\n)\n\nassert md.convert('linked.custom'), '<p><a href=\"http://linked.custom\">linked.custom</a></p>'\n```\n\n#### Example: Ignoring TLDs\n\n```python\nfrom mdx_linkify.mdx_linkify import LinkifyExtension\nfrom markdown import Markdown\n\ndef dont_linkify_net_tld(attrs, new=False):\n    if attrs[\"_text\"].endswith(\".net\"):\n        return None\n\n    return attrs\n\nmd = Markdown(\n    extensions=[LinkifyExtension(linker_options={\"callbacks\": [dont_linkify_net_tld]})],\n)\n\nassert md.convert(\"not-linked.net\"), '<p>not-linked.net</p>'\n```\n\n## Development\n\n```\ngit clone git@github.com:daGrevis/mdx_linkify.git\nvirtualenv mdx_linkify/\ncd mdx_linkify/\nsource bin/activate\npython setup.py install\npython setup.py test\n```\n\nPull requests are much welcome! :+1:\n\n## Releasing\n\n_(more like a cheatsheet for me actually)_\n\n- Change version in `setup.py`,\n- Commit and tag it,\n- Push it (including tag),\n- Run `python setup.py register && python setup.py sdist upload`;",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Link recognition for Python Markdown",
    "version": "2.1",
    "project_urls": {
        "Homepage": "https://github.com/daGrevis/mdx_linkify"
    },
    "split_keywords": [
        "markdown",
        "links"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "039ad07599b2e3487d4fa6dca76ecf80ae3d51d135c107d7ead09509a88ecc1d",
                "md5": "f32c7dd45524cdba923a68e58ee0f763",
                "sha256": "e09278e43e5076b63398238b069a361913779683183481e9206235667cd89f54"
            },
            "downloads": -1,
            "filename": "mdx_linkify-2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "f32c7dd45524cdba923a68e58ee0f763",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4315,
            "upload_time": "2020-11-09T16:42:30",
            "upload_time_iso_8601": "2020-11-09T16:42:30.142784Z",
            "url": "https://files.pythonhosted.org/packages/03/9a/d07599b2e3487d4fa6dca76ecf80ae3d51d135c107d7ead09509a88ecc1d/mdx_linkify-2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-11-09 16:42:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "daGrevis",
    "github_project": "mdx_linkify",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "mdx-linkify"
}
        
Elapsed time: 4.29724s