diff --git a/app/__init__.py b/app/__init__.py index 01c0872..b54a62e 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -40,10 +40,11 @@ def create_admin(): def create_deleted_user(): username = "DeletedUser" - if Users.count({"username": username}) == 0: + if Users.count({"username": username.lower()}) == 0: print("Creating DeletedUser") Users.create({ - "username": username, + "username": username.lower(), + "display_name": username, "password_hash": "", "permission": PermissionLevel.SYSTEM.value, }) @@ -61,7 +62,7 @@ def reparse_babycode(): with db.transaction(): for ph in post_histories: ph.update({ - 'content': babycode_to_html(ph['original_markup']), + 'content': babycode_to_html(ph['original_markup']).result, 'format_version': BABYCODE_VERSION, }) print('Re-parsing posts done.') @@ -76,7 +77,7 @@ def reparse_babycode(): with db.transaction(): for user in users_with_sigs: user.update({ - 'signature_rendered': babycode_to_html(user['signature_original_markup']), + 'signature_rendered': babycode_to_html(user['signature_original_markup']).result, 'signature_format_version': BABYCODE_VERSION, }) print(f'Re-parsed {len(users_with_sigs)} user sigs.') @@ -90,7 +91,7 @@ def reparse_babycode(): with db.transaction(): for motd in stale_motds: motd.update({ - 'body_rendered': babycode_to_html(motd['body_original_markup'], banned_tags=MOTD_BANNED_TAGS), + 'body_rendered': babycode_to_html(motd['body_original_markup'], banned_tags=MOTD_BANNED_TAGS).result, 'format_version': BABYCODE_VERSION, }) print('Re-parsing MOTDs done.') @@ -206,7 +207,7 @@ def create_app(): @app.template_filter('babycode') def babycode_filter(markup): - return babycode_to_html(markup) + return babycode_to_html(markup).result @app.template_filter('extract_h2') def extract_h2(content): diff --git a/app/constants.py b/app/constants.py index 495d4d3..e2f2081 100644 --- a/app/constants.py +++ b/app/constants.py @@ -48,7 +48,7 @@ REACTION_EMOJI = [ ] MOTD_BANNED_TAGS = [ - 'img', 'spoiler', + 'img', 'spoiler', 'mention' ] def permission_level_string(perm): diff --git a/app/lib/babycode.py b/app/lib/babycode.py index b622c79..58bbfe4 100644 --- a/app/lib/babycode.py +++ b/app/lib/babycode.py @@ -6,6 +6,16 @@ from pygments.lexers import get_lexer_by_name from pygments.util import ClassNotFound as PygmentsClassNotFound import re +class BabycodeParseResult: + def __init__(self, result, mentions=[]): + self.result = result + self.mentions = mentions + + + def __str__(self): + return self.result + + BABYCODE_VERSION = 5 NAMED_COLORS = [ @@ -78,6 +88,9 @@ def tag_list(children): return " ".join([f"
[img=https://forum.poto.cafe/avatars/default.webp]the Python logo with a cowboy hat[/img]
{{ '[img=/static/avatars/default.webp]the Python logo with a cowboy hat[/img]' | babycode | safe }}
- Text inside the tag becomes the alt text. The attribute is the image URL. The text inside the tag will become the image's alt text.
+The attribute is the image URL. The text inside the tag will become the image's alt text.
Images will always break up a paragraph and will get scaled down to a maximum of 400px. However, consecutive image tags will try to stay in one line, wrapping if necessary. Break the paragraph if you wish to keep images on their own paragraph.
Multiple images attached to a post can be clicked to open a dialog to view them.
@@ -157,13 +157,22 @@ {{ list | babycode | safe }}You can make a section collapsible by using the [spoiler] tag:
You can make a section collapsible by using the [spoiler] tag:
You can mention users by their username (not their display name) by using @username. A user's username is always shown below their avatar and display name on their posts and their user page.
A mention will show up on your post as a clickable box with the user's display name if they have one set or their username with an @ symbol if they don't:
Mentioning a user does not notify them. It is simply a way to link to their profile in your posts.
[{{ tag }}]{{ tag }}You have been invited by {{ inviter.username }} to join {{ config.SITE_NAME }}. Create an identity below.
+You have been invited by {{ inviter.get_readable_name() }} to join {{ config.SITE_NAME }}. Create an identity below.
{% endif %}