Hi,
I'm having fun with shortcodes and (if I'm not missing something obvious) there are issues with the way white space is handled.
Here is my shortcode for creating a little aside thingy (note the wrapping for readability inside the template literal):
eleventyConfig.addPairedShortcode('note', function (content, title) {
const slug = slugify(title).toLowerCase();
return `
<aside aria-labelledby="${slug}">
<h4 id="${slug}">${title}</h4>
${content}
</aside>
`;
});
Using
{% note 'Title' %}
Some text.
Some other text
{% endnote %}
I get
<pre><code> <aside aria-labelledby="title">
<h4 id="title">Title</h4>
</code></pre>
<p>Some text.</p>
<p>Some other text</p>
<pre><code> </aside>
</code></pre>
Weird, because it encodes and renders as a <pre>. So I tried removing the white space with the hyphens:
{%- note 'Title' -%}
Some text.
Some other text
{%- endnote -%}
The result is... different:
<aside aria-labelledby="title">
<h4 id="title">Title</h4>
Some text.</p>
<p>Some other text
</aside>
Looks like all the white space is collapsed, so my two markdown paragraphs are broken. The only way I seem to be able to fix it is by putting the template on one line (and not using the nunjucks white space removal):
eleventyConfig.addPairedShortcode('note', function (content, title) {
const slug = slugify(title).toLowerCase();
return `<aside aria-labelledby="${slug}"><h4 id="${slug}">${title}</h4>${content}</aside>`;
});
Is there something else to manage this? Perhaps I need to switch to a different template language?
Hi,
I'm having fun with shortcodes and (if I'm not missing something obvious) there are issues with the way white space is handled.
Here is my shortcode for creating a little aside thingy (note the wrapping for readability inside the template literal):
Using
{% note 'Title' %} Some text. Some other text {% endnote %}I get
Weird, because it encodes and renders as a
<pre>. So I tried removing the white space with the hyphens:{%- note 'Title' -%} Some text. Some other text {%- endnote -%}The result is... different:
Looks like all the white space is collapsed, so my two markdown paragraphs are broken. The only way I seem to be able to fix it is by putting the template on one line (and not using the nunjucks white space removal):
Is there something else to manage this? Perhaps I need to switch to a different template language?