diff --git a/app/lib/babycode.py b/app/lib/babycode.py
index abfc23b..8b3c7e2 100644
--- a/app/lib/babycode.py
+++ b/app/lib/babycode.py
@@ -63,6 +63,12 @@ def tag_color(children, attr):
# return just the way it was if we can't parse it
return f"[color={attr}]{children}[/color]"
+def tag_spoiler(children, attr):
+ spoiler_name = attr if attr else "Spoiler"
+ content = f"
{children}
"
+ container = f"""{content}
"""
+ return container
+
TAGS = {
"b": lambda children, attr: f"{children}",
"i": lambda children, attr: f"{children}",
@@ -82,6 +88,8 @@ TAGS = {
"center": lambda children, attr: f"{children}
",
"right": lambda children, attr: f"{children}
",
+
+ "spoiler": tag_spoiler,
}
def make_emoji(name, code):
diff --git a/app/templates/babycode.html b/app/templates/babycode.html
index d161d61..3b67dc6 100644
--- a/app/templates/babycode.html
+++ b/app/templates/babycode.html
@@ -151,6 +151,14 @@
Will produce the following list:
{{ list | babycode | safe }}
+
+ Spoilers
+ {% set spoiler = "[spoiler]My hidden content[/spoiler]" %}
+ You can make a section collapsible by using the [spoiler]
tag:
+ {{ ("[code]\n%s[/code]" % spoiler) | babycode | safe }}
+ Will produce:
+ {{ spoiler | babycode | safe }}
+
{% endset %}
{{ sections | safe }}
diff --git a/data/static/js/babycode-editor.js b/data/static/js/babycode-editor.js
index 6b8eccb..41e9acd 100644
--- a/data/static/js/babycode-editor.js
+++ b/data/static/js/babycode-editor.js
@@ -173,5 +173,8 @@
const json_resp = await req.json();
previewContainer.innerHTML = json_resp.html;
previewErrorsContainer.textContent = "";
+
+ const accordionRefreshEvt = new CustomEvent("refresh_accordions");
+ document.body.dispatchEvent(accordionRefreshEvt);
});
}
diff --git a/data/static/js/ui.js b/data/static/js/ui.js
index 03b2351..0c4d7fd 100644
--- a/data/static/js/ui.js
+++ b/data/static/js/ui.js
@@ -110,21 +110,34 @@ document.addEventListener("DOMContentLoaded", () => {
});
// accordions
- const accordions = document.querySelectorAll(".accordion");
- accordions.forEach(accordion => {
+ const handledAccordions = new Set();
+ function attachAccordionHandlers(accordion){
+ if(handledAccordions.has(accordion)) {
+ return;
+ }
+
+ handledAccordions.add(accordion)
const header = accordion.querySelector(".accordion-header");
const toggleButton = header.querySelector(".accordion-toggle");
const content = accordion.querySelector(".accordion-content");
-
+
const toggle = (e) => {
e.stopPropagation();
accordion.classList.toggle("hidden");
content.classList.toggle("hidden");
toggleButton.textContent = content.classList.contains("hidden") ? "+" : "-"
}
-
+
toggleButton.addEventListener("click", toggle);
- });
+ }
+
+ function refreshAccordions(){
+ const accordions = document.querySelectorAll(".accordion");
+ accordions.forEach(attachAccordionHandlers);
+ }
+ refreshAccordions()
+
+ document.body.addEventListener('refresh_accordions', refreshAccordions)
//lightboxes
lightboxObj = constructLightbox();
diff --git a/data/static/style.css b/data/static/style.css
index cc2ffe7..92f5d53 100644
--- a/data/static/style.css
+++ b/data/static/style.css
@@ -786,6 +786,12 @@ ul, ol {
display: none;
}
+.post-accordion-content {
+ padding-top: 10px;
+ padding-bottom: 10px;
+ background-color: rgb(173.5214173228, 183.6737007874, 161.0262992126);
+}
+
.inbox-container {
padding: 10px;
}
diff --git a/sass/style.scss b/sass/style.scss
index f198c9e..377ebfe 100644
--- a/sass/style.scss
+++ b/sass/style.scss
@@ -781,6 +781,12 @@ ul, ol {
display: none;
}
+.post-accordion-content {
+ padding-top: 10px;
+ padding-bottom: 10px;
+ background-color: $main_bg;
+}
+
.inbox-container {
padding: 10px;
}