draw the rest of the owl

This commit is contained in:
2025-12-14 07:14:00 +03:00
parent 0898c56a51
commit d4e3d7cded
16 changed files with 258 additions and 22 deletions

View File

@@ -190,7 +190,7 @@ class RSSXMLRenderer(BabycodeRenderer):
def __init__(self, fragment=False):
super().__init__(RSS_TAGS, VOID_TAGS, RSS_EMOJI, fragment)
def make_mention(self, element):
def make_mention(self, e):
from ..models import Users
from flask import url_for, current_app
with current_app.test_request_context('/'):
@@ -410,10 +410,28 @@ def tag_code_rss(children, attr):
else:
return f'<pre><code>{children}</code></pre>'
def tag_url_rss(children, attr):
if attr.startswith('/'):
from flask import current_app
uri = f"{current_app.config['PREFERRED_URL_SCHEME']}://{current_app.config['SERVER_NAME']}{attr}"
return f"<a href={uri}>{children}</a>"
return f"<a href={attr}>{children}</a>"
def tag_image_rss(children, attr):
if attr.startswith('/'):
from flask import current_app
uri = f"{current_app.config['PREFERRED_URL_SCHEME']}://{current_app.config['SERVER_NAME']}{attr}"
return f'<img src="{uri}" alt={children} />'
return f'<img src="{attr}" alt={children} />'
RSS_TAGS = {
**TAGS,
'img': lambda children, attr: f'<img src="{attr}" alt={children} />',
'spoiler': lambda children, attr: f'<details><summary>{attr or "Spoiler"}</summary>{children}</details>',
'img': tag_image_rss,
'url': tag_url_rss,
'spoiler': lambda children, attr: f'<details><summary>{attr or "Spoiler"} (click to reveal)</summary>{children}</details>',
'code': tag_code_rss,
'big': lambda children, attr: f'<span style="font-size: 1.2em">{children}</span>',
@@ -424,6 +442,7 @@ VOID_TAGS = {
'lb': lambda attr: '[',
'rb': lambda attr: ']',
'@': lambda attr: '@',
'-': lambda attr: '-',
}
# [img] is considered block for the purposes of collapsing whitespace,
@@ -544,7 +563,7 @@ def babycode_ast(s: str, banned_tags=[]):
return elements
def babycode_to_html(s: str, banned_tags=[], fragment=False):
def babycode_to_html(s: str, banned_tags=[], fragment=False) -> BabycodeRenderResult:
"""
transforms a string of babycode into html.
@@ -561,7 +580,7 @@ def babycode_to_html(s: str, banned_tags=[], fragment=False):
return r.render(ast)
def babycode_to_rssxml(s: str, banned_tags=[], fragment=False):
def babycode_to_rssxml(s: str, banned_tags=[], fragment=False) -> str:
"""
transforms a string of babycode into rss-compatible x/html.