New logo's new sizes markdown stripper.py

This commit is contained in:
retoor 2025-06-06 14:46:59 +02:00
parent 66b36509d2
commit ae26181cf8
12 changed files with 22 additions and 6 deletions

View File

@ -1,6 +1,6 @@
from snek.system.model import now
from snek.system.service import BaseService
from snek.system.markdown import strip_markdown
class NotificationService(BaseService):
mapper_name = "notification"
@ -64,11 +64,13 @@ class NotificationService(BaseService):
if channel_member["user_uid"] != user["uid"]:
try:
stripped_message = strip_markdown(channel_message["message"])
channel_name = channel_member.get_name()
await self.app.services.push.notify_user(
user_uid=channel_member["user_uid"],
payload={
"title": f"New message in {channel_member['label']}",
"message": f"{user['nick']}: {channel_message['message']}",
"title": f"New message in {channel_member}",
"message": f"{user['nick']}: {stripped_message}",
"icon": "/image/snek192.png",
"url": f"/channel/{channel_message['channel_uid']}.html",
},

Binary file not shown.

After

(image error) Size: 1.3 MiB

Binary file not shown.

After

(image error) Size: 17 KiB

Binary file not shown.

After

(image error) Size: 25 KiB

Binary file not shown.

After

(image error) Size: 79 KiB

Binary file not shown.

After

(image error) Size: 3.2 KiB

Binary file not shown.

After

(image error) Size: 132 KiB

Binary file not shown.

After

(image error) Size: 5.9 KiB

Binary file not shown.

After

(image error) Size: 9.0 KiB

Binary file not shown.

After

(image error) Size: 1.3 MiB

View File

@ -17,12 +17,12 @@
"start_url": "/web.html",
"icons": [
{
"src": "/image/snek192.png",
"src": "/image/snek_logo_192x192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/image/snek512.png",
"src": "/image/snek_logo_512x512.png",
"type": "image/png",
"sizes": "512x512"
}

View File

@ -1,5 +1,5 @@
# Original source: https://brandonjay.dev/posts/2021/render-markdown-html-in-python-with-jinja2
import re
from types import SimpleNamespace
from app.cache import time_cache_async
@ -12,6 +12,20 @@ from pygments.formatters import html
from pygments.lexers import get_lexer_by_name
def strip_markdown(md_text):
# Remove code blocks (
md_text = re.sub(r'[\s\S]?```', '', md_text)
md_text = re.sub(r'^\s{4,}.$', '', md_text, flags=re.MULTILINE)
md_text = re.sub(r'^\s{0,3}#{1,6}\s+', '', md_text, flags=re.MULTILINE)
md_text = re.sub(r'!\[.?\]\(.?\)', '', md_text)
md_text = re.sub(r'\[([^\]]+)\]\(.?\)', r'\1', md_text)
md_text = re.sub(r'(\*|_){1,3}(.+?)\1{1,3}', r'\2', md_text)
md_text = re.sub(r'^\s{0,3}>+\s?', '', md_text, flags=re.MULTILINE)
md_text = re.sub(r'^(\s)(\-{3,}|_{3,}|\{3,})\s$', '', md_text, flags=re.MULTILINE)
md_text = re.sub(r'[`~>#+\-=]', '', md_text)
md_text = re.sub(r'\s+', ' ', md_text)
return md_text.strip()
class MarkdownRenderer(HTMLRenderer):
_allow_harmful_protocols = False