fix unicode hashtag

pull/16/head
Chaiwat Suttipongsakul 2019-02-24 21:36:06 +07:00
rodzic 26e65f976d
commit d73c79b2ba
3 zmienionych plików z 10 dodań i 3 usunięć

Wyświetl plik

@ -1,10 +1,11 @@
import re
from typing import Dict
from typing import List
from typing import Tuple
from markdown import markdown
import regex as re
from .activitypub import get_backend
from .webfinger import get_actor_url
@ -24,7 +25,10 @@ MENTION_REGEX = re.compile(r"@[\d\w_.+-]+@[\d\w-]+\.[\d\w\-.]+")
def hashtagify(content: str) -> Tuple[str, List[Dict[str, str]]]:
base_url = get_backend().base_url()
tags = []
for hashtag in re.findall(HASHTAG_REGEX, content):
hashtags = re.findall(HASHTAG_REGEX, content)
hashtags.sort()
hashtags.reverse() # replace longest tags first
for hashtag in hashtags:
tag = hashtag[1:]
link = f'<a href="{base_url}/tags/{tag}" class="mention hashtag" rel="tag">#<span>{tag}</span></a>'
tags.append(dict(href=f"{base_url}/tags/{tag}", name=hashtag, type="Hashtag"))

Wyświetl plik

@ -5,3 +5,4 @@ markdown
pyld
pycryptodome
html2text
regex

Wyświetl plik

@ -1,11 +1,12 @@
#!/usr/bin/env python
from distutils.core import setup
import io
import os
from distutils.core import setup
from setuptools import find_packages
here = os.path.abspath(os.path.dirname(__file__))
@ -29,6 +30,7 @@ REQUIRED = [
"pycryptodome",
"html2text",
"mdx_linkify",
"regex",
]
DEPENDENCY_LINKS = []