From 60378b0b6d844a5f7cb87502243032d19cc1c617 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 31 Jan 2023 10:24:57 -0500 Subject: [PATCH] spoiler --- catalog/static/catalog.js | 5 +++++ catalog/templates/item_base.html | 4 ++-- catalog/templates/item_mark_list.html | 2 +- common/static/sass/_MdContent.sass | 14 ++++++++------ journal/models.py | 10 +++++++++- journal/renderers.py | 18 ++++++++++++++++-- journal/templates/list_item_base.html | 2 +- .../templates/activity/create_collection.html | 14 +------------- social/templates/activity/like_collection.html | 12 ------------ social/templates/activity/mark_item.html | 2 +- 10 files changed, 44 insertions(+), 39 deletions(-) diff --git a/catalog/static/catalog.js b/catalog/static/catalog.js index e703fa80..705fb928 100644 --- a/catalog/static/catalog.js +++ b/catalog/static/catalog.js @@ -36,6 +36,11 @@ function catalog_init(context) { $(this).parent().siblings(".entity-desc__content").removeClass('entity-desc__content--folded'); $(this).parent(".entity-desc__unfold-button").remove(); }); + + // spoiler + $(".spoiler", context).on('click', function(){ + $(this).toggleClass('revealed'); + }) } $(function() { diff --git a/catalog/templates/item_base.html b/catalog/templates/item_base.html index fc081d49..26ff20d7 100644 --- a/catalog/templates/item_base.html +++ b/catalog/templates/item_base.html @@ -149,7 +149,7 @@ {% endif %} {% if others_mark.text %} -

{{ others_mark.text }}

+

{{ others_mark.comment_html|safe }}

{% endif %} {% empty %} @@ -222,7 +222,7 @@ {% if mark.text %} -

{{ mark.text }}

+

{{ mark.comment_html|safe }}

{% endif %}
diff --git a/catalog/templates/item_mark_list.html b/catalog/templates/item_mark_list.html index b7a3f50d..eeb61650 100644 --- a/catalog/templates/item_mark_list.html +++ b/catalog/templates/item_mark_list.html @@ -51,7 +51,7 @@ {% endif %} {% if others_mark.mark.text %} -

{{ others_mark.mark.text }}

+

{{ others_mark.mark.comment_html|safe }}

{% endif %} {% empty %} diff --git a/common/static/sass/_MdContent.sass b/common/static/sass/_MdContent.sass index ebfa1c45..79bac1ad 100644 --- a/common/static/sass/_MdContent.sass +++ b/common/static/sass/_MdContent.sass @@ -64,10 +64,12 @@ background: unset; text-decoration: underline; - & .spoiler - filter: blur(8px); - cursor: pointer; +.spoiler + background: grey; + filter: blur(2px); + cursor: pointer; - & .spoiler .revealed - filter: unset; - color: inherit; +.spoiler.revealed + background: unset; + filter: unset; + color: inherit; diff --git a/journal/models.py b/journal/models.py index c5979ba9..caf2ab2b 100644 --- a/journal/models.py +++ b/journal/models.py @@ -22,7 +22,7 @@ from django.utils.baseconv import base62 from django.db.models import Q from catalog.models import * from django.contrib.contenttypes.models import ContentType -from .renderers import render_md +from .renderers import render_md, render_text from catalog.common import jsondata from journal import renderers @@ -188,6 +188,10 @@ class Memo(Content): class Comment(Content): text = models.TextField(blank=False, null=False) + @property + def html(self): + return render_text(self.text) + @staticmethod def comment_item_by_user(item, user, text, visibility=0): comment = Comment.objects.filter(owner=user, item=item).first() @@ -949,6 +953,10 @@ class Mark: def text(self): return self.comment.text if self.comment else None + @property + def comment_html(self): + return self.comment.html if self.comment else None + @cached_property def review(self): return Review.objects.filter(owner=self.owner, item=self.item).first() diff --git a/journal/renderers.py b/journal/renderers.py index 1110e689..d6aaa01e 100644 --- a/journal/renderers.py +++ b/journal/renderers.py @@ -1,7 +1,7 @@ from typing import cast import mistune import re - +from django.utils.html import escape MARKDOWNX_MARKDOWNIFY_FUNCTION = "journal.renderers.render_md" @@ -30,5 +30,19 @@ def render_md(s) -> str: return cast(str, _markdown(s)) +def _spolier(s): + l = s.split(">!", 1) + if len(l) == 1: + return escape(s) + r = l[1].split("!<", 1) + return ( + escape(l[0]) + + '' + + escape(r[0]) + + "" + + (_spolier(r[1]) if len(r) == 2 else "") + ) + + def render_text(s): - return mistune.html(s) + return _spolier(s) diff --git a/journal/templates/list_item_base.html b/journal/templates/list_item_base.html index 4b6ab438..e5b27a0d 100644 --- a/journal/templates/list_item_base.html +++ b/journal/templates/list_item_base.html @@ -96,7 +96,7 @@

  {% if mark.text %} - {{ mark.text }} + {{ mark.comment_html|safe }} {% endif %}

diff --git a/social/templates/activity/create_collection.html b/social/templates/activity/create_collection.html index fa4f1b3a..aa1e4aa0 100644 --- a/social/templates/activity/create_collection.html +++ b/social/templates/activity/create_collection.html @@ -44,17 +44,5 @@ {% endfor %}

- {% if activity.review %} - {{ activity.review.title }} - {% endif %} - {% if activity.mark %} - {% if activity.mark.rating %} - - {% endif %} - - {% if activity.mark.text %} -

{{ activity.mark.text }}

- {% endif %} - {% endif %}

- \ No newline at end of file + diff --git a/social/templates/activity/like_collection.html b/social/templates/activity/like_collection.html index 5dc9da7d..9c8cad7b 100644 --- a/social/templates/activity/like_collection.html +++ b/social/templates/activity/like_collection.html @@ -42,17 +42,5 @@

- {% if activity.review %} - {{ activity.review.title }} - {% endif %} - {% if activity.mark %} - {% if activity.mark.rating %} - - {% endif %} - - {% if activity.mark.text %} -

{{ activity.mark.text }}

- {% endif %} - {% endif %}

diff --git a/social/templates/activity/mark_item.html b/social/templates/activity/mark_item.html index 6bd60537..da4f5843 100644 --- a/social/templates/activity/mark_item.html +++ b/social/templates/activity/mark_item.html @@ -53,7 +53,7 @@ {% endif %} {% if activity.action_object.mark.text %} -

{{ activity.action_object.mark.text }}

+

{{ activity.action_object.mark.comment_html|safe }}

{% endif %}