fix: do not require bleach module by default

Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
This commit is contained in:
Christopher Arndt 2023-07-23 23:54:03 +02:00
parent 1e374c61e6
commit 92d85d31bf
2 changed files with 26 additions and 11 deletions

View File

@ -70,6 +70,9 @@ steps:
substtution is considered to be in Markdown format and will be rendered to
HTML and sent as a formatted message with `org.matrix.custom.html` format.
Using this feature requires the `markdown` and `bleach` Python modules to
be available (the plugin's docker image has them installed).
* `markdown_extensions` *(default:* `admonition, extra, sane_lists, smarty`)
Comma-separated list of enabled Markdown extensions. See this
@ -107,8 +110,8 @@ steps:
ID of user on homeserver to send message as (ID, not username).
[`DEFAULT_ALLOWED_ATTRS`]: ./matrixchat-notify.py#L29
[`DEFAULT_ALLOWED_TAGS`]: ./matrixchat-notify.py#L35
[`DEFAULT_ALLOWED_ATTRS`]: ./matrixchat-notify.py#L27
[`DEFAULT_ALLOWED_TAGS`]: ./matrixchat-notify.py#L34
[allowed attributes]: https://bleach.readthedocs.io/en/latest/clean.html#allowed-attributes-attributes
[drone.io]: https://drone.io/
[list of extensions]: https://python-markdown.github.io/extensions/

View File

@ -20,36 +20,47 @@ from distutils.util import strtobool
from os.path import exists
from string import Template
import bleach
from nio import AsyncClient, LoginResponse
PROG = "matrixchat-notify"
CONFIG_FILENAME = f"{PROG}-config.json"
DEFAULT_ALLOWED_ATTRS = bleach.ALLOWED_ATTRIBUTES.copy()
DEFAULT_ALLOWED_ATTRS.update(
{
"*": ["class"],
"img": ["alt", "src"],
}
)
DEFAULT_ALLOWED_TAGS = bleach.ALLOWED_TAGS | {
DEFAULT_ALLOWED_ATTRS = {
"*": ["class"],
"a": ["href", "title"],
"abbr": ["title"],
"acronym": ["title"],
"img": ["alt", "src"],
}
DEFAULT_ALLOWED_TAGS = {
"a",
"abbr",
"acronym",
"b",
"blockquote",
"code",
"dd",
"div",
"dl",
"dt",
"em",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"i",
"li",
"ol",
"p",
"span",
"strong",
"table",
"td",
"th",
"thead",
"tr",
"ul",
}
DEFAULT_HOMESERVER = "https://matrix.org"
DEFAULT_MARKDOWN_EXTENSIONS = "admonition, extra, sane_lists, smarty"
@ -171,6 +182,7 @@ def render_message(config):
def render_markdown(message, config):
import bleach
import markdown
allowed_attrs = config.get("allowed_attrs", DEFAULT_ALLOWED_ATTRS)