Add Q&A accordion paired shortcode

This commit is contained in:
Helen Chong 2024-05-07 09:53:49 +08:00
parent abe5e13898
commit 7c99ec4ae6
1 changed files with 14 additions and 5 deletions

View File

@ -81,13 +81,22 @@ module.exports = function (eleventyConfig) {
// Paired shorcode: Spoiler accordion // Paired shorcode: Spoiler accordion
eleventyConfig.addPairedShortcode('spoiler', (content, hint) => { eleventyConfig.addPairedShortcode('spoiler', (content, hint) => {
content = content.trim(); const hintMarkup = markdownLibrary.renderInline(hint);
const hintMarkUp = markdownLibrary.renderInline(hint);
const contentMarkup = markdownLibrary.render(content); const contentMarkup = markdownLibrary.render(content);
return `<details class="spoiler-accordion"> return `<details class="spoiler-accordion">
<summary class="spoiler-accordion__hint">${hintMarkUp}</summary> <summary class="spoiler-accordion__hint">${hintMarkup}</summary>
<div class="spoiler-accordion__spoiler">${contentMarkup}</div> <div class="spoiler-accordion__spoiler">${contentMarkup}</div>
</details>`; </details>`;
});
// Paired shorcode: Q&A accordion
eleventyConfig.addPairedShortcode('qna', (answer, question) => {
const questionMarkup = markdownLibrary.renderInline(question);
const answerMarkup = markdownLibrary.render(answer);
return `<details class="qna-accordion">
<summary class="qna-accordion__question">${questionMarkup}</summary>
<div class="qna-accordion__answer">${answerMarkup}</div>
</details>`;
}); });
/* This is the part that tells 11ty to swap to our custom config */ /* This is the part that tells 11ty to swap to our custom config */