diff --git a/CHANGELOG.md b/CHANGELOG.md index 35d0863..baff78f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- add formatted_body to bypass markdown with direct + [matrix-custom-HTML](https://matrix.org/docs/spec/client_server/r0.6.1#m-room-message-msgtypes) - allow "key" to be passed as a parameter - rename "text" to "body". diff --git a/matrix_webhook/__main__.py b/matrix_webhook/__main__.py index 17305cc..005a3eb 100644 --- a/matrix_webhook/__main__.py +++ b/matrix_webhook/__main__.py @@ -54,12 +54,17 @@ async def handler(request): if data["key"] != conf.API_KEY: return create_json_response(HTTPStatus.UNAUTHORIZED, "Invalid API key") + if "formatted_body" in data: + formatted_body = data["formatted_body"] + else: + formatted_body = markdown(str(data["body"]), extensions=["extra"]) + room_id = request.path[1:] content = { "msgtype": "m.text", "body": data["body"], "format": "org.matrix.custom.html", - "formatted_body": markdown(str(data["body"]), extensions=["extra"]), + "formatted_body": formatted_body, } for _ in range(10): try: diff --git a/tests/tests.py b/tests/tests.py index 2bc97e3..9a82cc9 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -78,6 +78,32 @@ class BotTest(unittest.IsolatedAsyncioTestCase): self.assertEqual(message.body, body) self.assertEqual(message.formatted_body, "