add spoiler tag to babycode
This commit is contained in:
@ -63,6 +63,12 @@ def tag_color(children, attr):
|
|||||||
# return just the way it was if we can't parse it
|
# return just the way it was if we can't parse it
|
||||||
return f"[color={attr}]{children}[/color]"
|
return f"[color={attr}]{children}[/color]"
|
||||||
|
|
||||||
|
def tag_spoiler(children, attr):
|
||||||
|
spoiler_name = attr if attr else "Spoiler"
|
||||||
|
content = f"<div class='accordion-content post-accordion-content hidden'>{children}</div>"
|
||||||
|
container = f"""<div class='accordion hidden'><div class='accordion-header'><button type='button' class='accordion-toggle'>+</button><span>{spoiler_name}</span></div>{content}</div>"""
|
||||||
|
return container
|
||||||
|
|
||||||
TAGS = {
|
TAGS = {
|
||||||
"b": lambda children, attr: f"<strong>{children}</strong>",
|
"b": lambda children, attr: f"<strong>{children}</strong>",
|
||||||
"i": lambda children, attr: f"<em>{children}</em>",
|
"i": lambda children, attr: f"<em>{children}</em>",
|
||||||
@ -82,6 +88,8 @@ TAGS = {
|
|||||||
|
|
||||||
"center": lambda children, attr: f"<div style='text-align: center;'>{children}</div>",
|
"center": lambda children, attr: f"<div style='text-align: center;'>{children}</div>",
|
||||||
"right": lambda children, attr: f"<div style='text-align: right;'>{children}</div>",
|
"right": lambda children, attr: f"<div style='text-align: right;'>{children}</div>",
|
||||||
|
|
||||||
|
"spoiler": tag_spoiler,
|
||||||
}
|
}
|
||||||
|
|
||||||
def make_emoji(name, code):
|
def make_emoji(name, code):
|
||||||
|
@ -151,6 +151,14 @@
|
|||||||
Will produce the following list:
|
Will produce the following list:
|
||||||
{{ list | babycode | safe }}
|
{{ list | babycode | safe }}
|
||||||
</section>
|
</section>
|
||||||
|
<section class="babycode-guide-section">
|
||||||
|
<h2 id="spoilers">Spoilers</h2>
|
||||||
|
{% set spoiler = "[spoiler]My hidden content[/spoiler]" %}
|
||||||
|
<p>You can make a section collapsible by using the <code class="inline-code">[spoiler]</code> tag:</p>
|
||||||
|
{{ ("[code]\n%s[/code]" % spoiler) | babycode | safe }}
|
||||||
|
Will produce:
|
||||||
|
{{ spoiler | babycode | safe }}
|
||||||
|
</section>
|
||||||
{% endset %}
|
{% endset %}
|
||||||
{{ sections | safe }}
|
{{ sections | safe }}
|
||||||
</div>
|
</div>
|
||||||
|
@ -173,5 +173,8 @@
|
|||||||
const json_resp = await req.json();
|
const json_resp = await req.json();
|
||||||
previewContainer.innerHTML = json_resp.html;
|
previewContainer.innerHTML = json_resp.html;
|
||||||
previewErrorsContainer.textContent = "";
|
previewErrorsContainer.textContent = "";
|
||||||
|
|
||||||
|
const accordionRefreshEvt = new CustomEvent("refresh_accordions");
|
||||||
|
document.body.dispatchEvent(accordionRefreshEvt);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -110,8 +110,13 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// accordions
|
// accordions
|
||||||
const accordions = document.querySelectorAll(".accordion");
|
const handledAccordions = new Set();
|
||||||
accordions.forEach(accordion => {
|
function attachAccordionHandlers(accordion){
|
||||||
|
if(handledAccordions.has(accordion)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
handledAccordions.add(accordion)
|
||||||
const header = accordion.querySelector(".accordion-header");
|
const header = accordion.querySelector(".accordion-header");
|
||||||
const toggleButton = header.querySelector(".accordion-toggle");
|
const toggleButton = header.querySelector(".accordion-toggle");
|
||||||
const content = accordion.querySelector(".accordion-content");
|
const content = accordion.querySelector(".accordion-content");
|
||||||
@ -124,7 +129,15 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
toggleButton.addEventListener("click", toggle);
|
toggleButton.addEventListener("click", toggle);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
function refreshAccordions(){
|
||||||
|
const accordions = document.querySelectorAll(".accordion");
|
||||||
|
accordions.forEach(attachAccordionHandlers);
|
||||||
|
}
|
||||||
|
refreshAccordions()
|
||||||
|
|
||||||
|
document.body.addEventListener('refresh_accordions', refreshAccordions)
|
||||||
|
|
||||||
//lightboxes
|
//lightboxes
|
||||||
lightboxObj = constructLightbox();
|
lightboxObj = constructLightbox();
|
||||||
|
@ -786,6 +786,12 @@ ul, ol {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post-accordion-content {
|
||||||
|
padding-top: 10px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
background-color: rgb(173.5214173228, 183.6737007874, 161.0262992126);
|
||||||
|
}
|
||||||
|
|
||||||
.inbox-container {
|
.inbox-container {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
@ -781,6 +781,12 @@ ul, ol {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post-accordion-content {
|
||||||
|
padding-top: 10px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
background-color: $main_bg;
|
||||||
|
}
|
||||||
|
|
||||||
.inbox-container {
|
.inbox-container {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user