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

Support for shortcodes in fenced code blocks #1708

Closed
FIGBERT opened this issue Dec 25, 2021 · 9 comments
Closed

Support for shortcodes in fenced code blocks #1708

FIGBERT opened this issue Dec 25, 2021 · 9 comments
Labels
bug done in pr Already done in a PR

Comments

@FIGBERT
Copy link

FIGBERT commented Dec 25, 2021

Bug Report

Environment

Zola version: 0.15.2

Expected Behavior

Tell us what should have happened.

In previous versions of Zola, I was able to put shortcodes in fenced code blocks in order to give the viewer an idea of what the generated HTML of the shortcode would look like when used.

This is useful, for example, when giving examples of custom shortcodes in Zola themes.

Current Behavior

Tell us what happens instead of the expected behavior. If you are seeing an
error, please include the full error message and stack trace. You can get the
stacktrace of a panic by adding RUST_BACKTRACE=1 when running a zola command.

In the current version of Zola, these shortcodes just output @@ZOLA_SC_PLACEHOLDER@@.

Step to reproduce

Please provide the steps to reproduce the issue.
If the issue is hard to reproduce, please provide a sample repository or sample
that triggers the bug.

To view this in action, clone figbert/d3c3nt and run zola serve in the root directory. From there, navigate to /posts/rich-content/ and scroll around.

@Keats
Copy link
Collaborator

Keats commented Dec 26, 2021

Hm I didn't think anyone was using shortcodes in code blocks...

I believe for now you can fix it by not using a markdown code block:

<pre>
{{ audio(sources=["example.wav", "example.ogg", "example.mp3"]) }}
</pre>

(or whatever combination of pre/code you get with the Zola code blocks).

@FIGBERT
Copy link
Author

FIGBERT commented Dec 27, 2021

This doesn't appear to work – instead, it renders the shortcode within the pre tag. I've tried several different combinations of pre, code, and span, as well as several different browsers.

@Keats
Copy link
Collaborator

Keats commented Dec 29, 2021

ah yes it will not be escaped... I guess it needs to handle shortcodes in codeblocks too. If anyone wants to try, it should be self-contained to components/rendering/src/markdown.rs except for tests

@mjf
Copy link

mjf commented Jan 13, 2022

Hm I didn't think anyone was using shortcodes in code blocks...

But it's interesting idea, isn't it?! I'd definitely like to see this working too, please.

@liushuyu
Copy link
Contributor

I think this issue could be closed now? It's been fixed in #1720.

@Keats
Copy link
Collaborator

Keats commented Jan 13, 2022

I usually close on release to avoid duplicate issues. I put the Done tag to try to remember to close it at that point ;)

@Keats Keats added the done in pr Already done in a PR label Jan 13, 2022
@FIGBERT
Copy link
Author

FIGBERT commented Jan 23, 2022

Fixed in release 0.15.3! What a great community we've got here - thanks everyone for the quick patch.

@FIGBERT FIGBERT closed this as completed Jan 23, 2022
@lukehsiao
Copy link
Contributor

lukehsiao commented Nov 27, 2023

This still appears to be happening for me with zola 0.17.2

```text
{{example()}}
```

Results in

Error: Reason: Found usage of a shortcode named `example` but we do not know about. Make sure it's not a typo and that a field name `example.{html,md} exists in the `templates/shortcodes` directory.

Update: Hmm, perhaps this is actually working as intended.

In my case, I just want to display the literal text, not trigger a shortcode. Is there a way for me to escape this so that I just get the literal {{example()}}?

Update 2: 🤦 it's right there in the docs

Note that if you want to have some content that looks like a shortcode but not have Zola try to render it, you will need to escape it by using {{/* and */}} instead of {{ and }}.

Sorry for the noise, please ignore this comment.

@1player
Copy link

1player commented Jul 3, 2024

It does not happen only in code blocks. I used to have

<a name="contact-me" href="mailto:{{ email() }}">{{ email() }}</a>

where email is a shortcode, which used to work but the latest versions have broken it and it simply outputs @@ZOLA_SC_PLACEHOLDER@@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug done in pr Already done in a PR
Projects
None yet
Development

No branches or pull requests

6 participants