-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Allow nested shortcodes with markdown bodies #2630
Conversation
This looks awesome mate 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test using the nth
variable of shortcodes and nesting a shortcode in itself?
Thanks for taking a look at this! {{ a() }}
{{ a() }}
{% render_md() %}
{{ a() }}
{{ a() }}
{% render_md() %}
{{ a() }}
{{ a() }}
{% end %}
{% end %} Currently outputs <p>a: 1</p><p>a: 2</p><div><p>a: 1</p><p>a: 2</p><div><p>a: 1</p><p>a: 2</p></div></div> But am I correct to assume you'd rather have something like this? <p>a: 1</p><p>a: 2</p><div><p>a: 3</p><p>a: 4</p><div><p>a: 5</p><p>a: 6</p></div></div> Also, what do you mean by "nesting a shortcode in itself"? You still cannot define a shortcode that calls itself in its own body with this PR, and I can't think of a way to create a circular shortcode with these changes off the top of my head. |
Yes it would make more sense imo.
Kind of what you have in your example:
And make sure nth=1 for the outer one and nth=2 for the inner one |
* Have the markdown filter and site share a common ShortcodeInvocationCounter which is reset every page or section render * Fix typos with RwLock poison errors. * Have MarkdownFilter::filter use RenderContext::new * Make RenderContext::new more robust
Hey, I have implemented a Additionally, The nested shortcode invocations now have their
That said, since all shortcodes are parsed at one level before going in the inner level, if there are
Side-notes:
|
Hey @Keats, is there anything else you'd like from my end? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about putting RWLock everywhere. Can we just ignore the markdown filter?
@@ -212,14 +212,17 @@ impl Page { | |||
config: &Config, | |||
anchor_insert: InsertAnchor, | |||
shortcode_definitions: &HashMap<String, ShortcodeDefinition>, | |||
shortcode_invoke_counter: &ShortcodeInvocationCounter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that function is becoming unwieldly. Not an actionable thing, just noticing it
As far as I'm aware, partially due to the work put in place by #1358, shortcode execution within shortcodes is only possible with the markdown filter. Additionally, my personal use cases for this this PR is defining columns + rows, nested containers with different styles, etc. There are 2 main benefits to the use of RwLock as seen here.
There also doesn't seem to be many risks with the usage of RwLock as I've proposed.
|
@ARitz-Cracker i haven't forgotten about it, I just need to dedicate some time to that PR |
Ok I've spent some time on it finally, sorry for the delay. I think my concern is with trying to make the markdown filter a 1:1 with the markdown rendering of pages/sections. The filter currently supports shortcodes but in hindsight I think it was probably a mistake (as well as something super niche AFAIK). If you want Zola-CommonMark rendered, put it in a page with As an aside, I'm expecting macros/components to look a lot like shortcodes in the future (see Keats/tera2#51) so maybe we will be able to just template the markdown content instead of having our own parser/shortcodes handling which would be very nice. If you have any feedback on that, please comment. |
Hello @Keats , no worries for the delay, life happens, and I appreciate you taking a closer look. Generally, I think the ideas in As I've alluded to earlier, I also acknowledge that this PR contains some hacks to get around tera's current limitations and is far from the ideal solution when it comes to defining nested components written in markdown. That said I imagine that:
My motivation for this PR is to have a workable solution for being able to inline-define things like columns, grids, basically any situation that results in nested div's in multiple styles. I don't believe that misaligns with your vision of Zola as a whole, only that the underlying template system should have enabled the means to provide that functionality itself from the get-go, and I agree, but I'd like you to still consider merging the changes to the filter, as that can provide a comparable feature right now and in the meantime until the underlying requirements are complete for the more ideal solution. |
Nested shortcodes are completely fine, but why do you need it from the filter? What's the usecase there? I'd prefer to avoid changing code to add a feature that will be removed because people will start relying on it. |
To be honest, I pretty much just picked up from where from where #1475 left off and building upon the work of #1358. Though, now that you're saying that merge was a mistake, am I correct to assume that you would prefer having |
I think #1358 was the mistake. Ideally we would have nested shortcodes as you have them right now in this PR for pages/sections and do not do any changes to the filter. |
Is there a timeline for this merge? I'm working on my own website, and I will wait until this is merged if the time horizon is short enough(perhaps before 2025?). I can also try to contribute if there's any part that needs some work. |
I haven't had time to incorporate the feedback given due to a mix of work and personal obligations. This feature is important to projects I'm working on as well, though not immediately so. I may have time this Sunday Sunday the 1st, though I am more likely to have time on the weekend of the 7th. Then it's up to Keats to determine if the changes are satisfactory |
Does this work with non-body arguments too? I have a lot of inline shortcodes for styling that I can't currently nest. Some text with {{shortcode(t="{{nested(t='multiple formattings applied')}}")}} |
I don't think that would work but I could be wrong! |
Closing in favour of #2748 |
This PR will allow the use of nested shortcodes with markdown bodies. For example, with the shortcodes...
shortcodes/div_md.html
:<div>{{ body | markdown | safe }}</div>
shortcodes/quote.html
:<quote>{{body}}</quote>
Zola will now convert the following markdown...
...into the following HTML.
Fixes #515
I am assuming this is still a desired feature as the issue is still open.
Sanity check:
Code changes
templates::filters::MarkdownFilter
andsite::Site
have been changed to share a singleTera
instance using aRwLock
. This gives theMarkdownFilter
the ability to eventually call itself.{% end %}
, instead of the first-encountered{% end %}
. (Thanks to Allow recursively nested shortcodes #1475)cargo test --all
was ran prior to PR submissionnext
branch?If the change is a new feature or adding to/changing an existing one: