Tweak the linkifier

pull/14/head
Thomas Sileo 2018-07-29 20:49:11 +02:00
rodzic 35f7c4bf27
commit c4fb318d9d
3 zmienionych plików z 3 dodań i 5 usunięć

Wyświetl plik

@ -3,7 +3,6 @@ from typing import Dict
from typing import List
from typing import Tuple
from bleach.linkifier import Linker
from markdown import markdown
from .activitypub import get_backend
@ -18,7 +17,6 @@ def _set_attrs(attrs, new=False):
return attrs
LINKER = Linker(callbacks=[_set_attrs])
HASHTAG_REGEX = re.compile(r"(#[\d\w]+)")
MENTION_REGEX = re.compile(r"@[\d\w_.+-]+@[\d\w-]+\.[\d\w\-.]+")
@ -51,10 +49,9 @@ def mentionify(content: str) -> Tuple[str, List[Dict[str, str]]]:
def parse_markdown(content: str) -> Tuple[str, List[Dict[str, str]]]:
tags = []
content = LINKER.linkify(content)
content, hashtag_tags = hashtagify(content)
tags.extend(hashtag_tags)
content, mention_tags = mentionify(content)
tags.extend(mention_tags)
content = markdown(content)
content = markdown(content, extensions=["mdx_linkify"])
return content, tags

Wyświetl plik

@ -1,3 +1,4 @@
mdx_linkify
bleach
requests
markdown

Wyświetl plik

@ -21,7 +21,7 @@ REQUIRES_PYTHON = ">=3.6.0"
VERSION = None
REQUIRED = ["requests", "markdown", "bleach", "pyld", "pycryptodome", "html2text"]
REQUIRED = ["requests", "markdown", "bleach", "pyld", "pycryptodome", "html2text", "mdx_linkify"]
DEPENDENCY_LINKS = []