Skip to content

Commit

Permalink
Update readme (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutsu3 authored Jan 13, 2021
1 parent 3d2a467 commit c7c62c5
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![CI](https://github.com/tsutsu3/linkify-it-py/workflows/CI/badge.svg?branch=main)](https://github.com/tsutsu3/linkify-it-py/actions)
[![pypi](https://img.shields.io/pypi/v/linkify-it-py)](https://pypi.org/project/linkify-it-py/)
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/linkify-it-py/badges/version.svg)](https://anaconda.org/conda-forge/linkify-it-py)
[![codecov](https://codecov.io/gh/tsutsu3/linkify-it-py/branch/main/graph/badge.svg)](https://codecov.io/gh/tsutsu3/linkify-it-py)
[![Maintainability](https://api.codeclimate.com/v1/badges/6341fd3ec5f05fde392f/maintainability)](https://codeclimate.com/github/tsutsu3/linkify-it-py/maintainability)

Expand All @@ -25,6 +26,12 @@ Why it's awesome:
pip install linkify-it-py
```

or

```bash
conda install -c conda-forge linkify-it-py
```

## Usage examples

### Example 1. Simple use
Expand Down Expand Up @@ -82,28 +89,28 @@ print(linkify.match("Site tamanegi.onion!"))
### Example 3. Add twitter mentions handler

```python
from linkify import LinkfiyIt
from linkify_it import LinkifyIt


linkifyit = LinkifyIt()
linkify = LinkifyIt()

def validate(self, text, pos):
def validate(obj, text, pos):
tail = text[pos:]

if not self.re.get("twitter"):
self.re["twitter"] = re.compile(
"^([a-zA-Z0-9_]){1,15}(?!_)(?=$|" + self.re["src_ZPCc"] + ")"
if not obj.re.get("twitter"):
obj.re["twitter"] = re.compile(
"^([a-zA-Z0-9_]){1,15}(?!_)(?=$|" + obj.re["src_ZPCc"] + ")"
)
if self.re["twitter"].search(tail):
if obj.re["twitter"].search(tail):
if pos > 2 and tail[pos - 2] == "@":
return False
return len(self.re["twitter"].search(tail).group())
return len(obj.re["twitter"].search(tail).group())
return 0

def normalize(self, m):
m.url = "https://twitter.com/" + re.sub(r"^@", "", m.url)
def normalize(obj, match):
match.url = "https://twitter.com/" + re.sub(r"^@", "", match.url)

linkifyit.add("@", {"validate": validate, "normalize": normalize})
linkify.add("@", {"validate": validate, "normalize": normalize})
```


Expand Down

0 comments on commit c7c62c5

Please sign in to comment.