about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNguyễn Gia Phong <cnx@loang.net>2023-10-21 07:44:42 +0900
committerNguyễn Gia Phong <cnx@loang.net>2023-10-21 07:44:42 +0900
commit9392391dd580be60cb6e2efc2293db82b9e4badf (patch)
tree8d8acd78d9e8d0309426870867ea857087758456 /src
parenta632a4ccc505876144ae6ca8b3fd68cdf4bdb64a (diff)
downloadformbox-9392391dd580be60cb6e2efc2293db82b9e4badf.tar.gz
Replace dependencies 0.4.2
Bleach has been deprecated along with html5lib,
and its replacement nh3 lacks the linkify function,
so mistune is used for markdown for its url plugin.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/formbox.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/formbox.py b/src/formbox.py
index 3943401..236c473 100755
--- a/src/formbox.py
+++ b/src/formbox.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python
 # Format mbox as HTML/XML
-# Copyright (C) 2021-2022  Nguyễn Gia Phong
+# Copyright (C) 2021-2023  Nguyễn Gia Phong
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published
@@ -24,13 +24,14 @@ from mailbox import mbox
 from pathlib import Path
 from urllib.parse import quote, unquote, urlencode
 
-from bleach import clean, linkify
-from markdown import markdown
+from mistune import create_markdown
+from nh3 import clean
 
-sanitise = partial(clean, tags=('a', 'code', 'em', 'strong', 'sub', 'sup',
-                                'blockquote', 'p', 'pre', 'ul', 'ol', 'li'),
-                   protocols=('ftp', 'gemini', 'gopher', 'http', 'https',
-                              'irc', 'ircs', 'mailto', 'matrix', 'xmpp'))
+markdown = create_markdown(plugins=['url'])
+sanitise = partial(clean, tags={'a', 'code', 'em', 'strong', 'sub', 'sup',
+                                'blockquote', 'p', 'pre', 'ul', 'ol', 'li'},
+                   url_schemes={'ftp', 'gemini', 'gopher', 'http', 'https',
+                                'irc', 'ircs', 'mailto', 'matrix', 'xmpp'})
 
 
 def get_body(message):
@@ -40,7 +41,7 @@ def get_body(message):
             if payload is not None: return payload
     elif message.get_content_type() in ('text/markdown', 'text/plain'):
         payload = message.get_payload(decode=True).decode()
-        return sanitise(linkify(markdown(payload, output_format='html5')))
+        return sanitise(markdown(payload))
     return None