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 Dict
from typing import List from typing import List
from typing import Tuple from typing import Tuple
from markdown import markdown from markdown import markdown
import regex as re
from .activitypub import get_backend from .activitypub import get_backend
from .webfinger import get_actor_url 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]]]: def hashtagify(content: str) -> Tuple[str, List[Dict[str, str]]]:
base_url = get_backend().base_url() base_url = get_backend().base_url()
tags = [] 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:] tag = hashtag[1:]
link = f'<a href="{base_url}/tags/{tag}" class="mention hashtag" rel="tag">#<span>{tag}</span></a>' 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")) tags.append(dict(href=f"{base_url}/tags/{tag}", name=hashtag, type="Hashtag"))

Wyświetl plik

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

Wyświetl plik

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