Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using markdown inside a paired shortcode #536

Closed
chinchang opened this issue May 19, 2019 · 7 comments
Closed

Using markdown inside a paired shortcode #536

chinchang opened this issue May 19, 2019 · 7 comments
Labels
common-pitfall-eligible Might need to be listed on the common problems docs page documentation education
Milestone

Comments

@chinchang
Copy link

I am using a nunjucks paired shortcode in a markdown file. The markdown within the paired shortcode is returned as it is in the shortcode function. Is it possible to get the compiled output of markdown?

@zachleat
Copy link
Member

Yeah, I have run into this too and I don’t like it. 👍

@zachleat zachleat added the bug label Jun 18, 2019
@zachleat
Copy link
Member

I ran a bunch of tests for this and most of them worked. There was one particular case of this that I did run into which felt unintuitive but was actually technically correct.

Specifically, this worked:

# Title
{% testShortcode %}## Paired title{% endtestShortcode %}

with

module.exports = function(eleventyConfig) {
	eleventyConfig.addPairedShortcode("testShortcode", function(content) {
		return '## Test' + "\n" + content;
	})
};

This worked too:

# Title
{% testShortcode %}

with

module.exports = function(eleventyConfig) {
	eleventyConfig.addShortcode("testShortcode", function() {
		return '## Test';
	})
}

However, this didn’t work:

	eleventyConfig.addPairedShortcode("callout", function(content, level = "warn") {
		return `<div class="elv-callout elv-callout-${level}">${content}</div>`;
	});

via https://github.com/11ty/11ty.io/blob/master/.eleventy.js#L58

Usage:

{% callout "info" %}The <code>addPassthroughCopy</code> method… {% endcallout %}

Any nested content in there had to be HTML and not Markdown because it was wrapped in HTML in the shortcode.

This wouldn’t work:

{% callout "info" %}The `addPassthroughCopy` method… {% endcallout %}

BECAUSE the output would be:

<div class="elv-callout elv-callout-warn">The `addPassthroughCopy` method… </div>

And baseline markdown can’t embed markdown inside of HTML like that.

@zachleat
Copy link
Member

Does that make sense?

@zachleat zachleat added education and removed bug labels Jun 19, 2019
@zachleat
Copy link
Member

So, to circle back to your original request and the research above, please follow along at enhancement request #148 to allow you to parse markdown inside of your shortcode function itself.

zachleat added a commit that referenced this issue Jun 19, 2019
@zachleat
Copy link
Member

This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.

If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and I will reopen the issue. Thanks!

@zachleat zachleat added this to the Next Minor Version milestone Jun 19, 2019
zachleat added a commit to 11ty/11ty-website that referenced this issue Jun 20, 2019
@zachleat
Copy link
Member

@zachleat zachleat added common-pitfall-eligible Might need to be listed on the common problems docs page documentation labels Jun 20, 2019
@zachleat
Copy link
Member

Worth nothing that I added a workaround for this in my repo specifically https://github.com/11ty/11ty.io/blob/master/.eleventy.js#L59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common-pitfall-eligible Might need to be listed on the common problems docs page documentation education
Projects
None yet
Development

No branches or pull requests

2 participants