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

Fix shortcode handling in code-fences #1720

Merged
merged 2 commits into from
Jan 13, 2022

Conversation

liushuyu
Copy link
Contributor

@liushuyu liushuyu commented Jan 7, 2022

IMPORTANT: Please do not create a Pull Request adding a new feature without discussing it first.

The place to discuss new features is the forum: https://zola.discourse.group/
If you want to add a new feature, please open a thread there first in the feature requests section.

Sanity check:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code changes

(Delete or ignore this section for documentation changes)

  • Are you doing the PR on the next branch?

If the change is a new feature or adding to/changing an existing one:

  • [N/A] Have you created/updated the relevant documentation page(s)?

This should fix #1708.

The fix is actually a workaround: by applying and capturing shortcode rendering output and then re-render them inside the code-fence context.

@Keats
Copy link
Collaborator

Keats commented Jan 7, 2022

Can you add tests? It will need quite a few

@liushuyu
Copy link
Contributor Author

liushuyu commented Jan 8, 2022

Can you add tests? It will need quite a few

Sure, I will add some tests.

@liushuyu
Copy link
Contributor Author

liushuyu commented Jan 9, 2022

Rebased. Code cleaned-up. Tests added.

@liushuyu
Copy link
Contributor Author

This is basically a hack, but I think this is also the minimal changes required for fixing this issue.

There are three tests added to test the rendering behavior including a bulls**t all-star test to see whether the parser could correctly handle a bunch of weird constructs.

@liushuyu
Copy link
Contributor Author

Is this good to merge? Or should I do something more than this?

Copy link
Collaborator

@Keats Keats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small nit, no need to change it. Looks good, thanks!

@@ -242,7 +242,32 @@ pub fn markdown_to_html(
match event {
Event::Text(text) => {
if let Some(ref mut code_block) = code_block {
let html = code_block.highlight(&text);
let html;
if contains_shortcode(text.as_ref()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very small style neat but let html = if { .. } else { .. } is a bit nicer imo

@Keats Keats merged commit c1598dd into getzola:next Jan 13, 2022
Keats pushed a commit that referenced this pull request Jan 22, 2022
* rendering/markdown: fix shortcode handling in codefences

* rendering/tests: add a bunch of tests for codefence + shortcode usages
Keats pushed a commit that referenced this pull request Jan 23, 2022
* rendering/markdown: fix shortcode handling in codefences

* rendering/tests: add a bunch of tests for codefence + shortcode usages
thomasantony pushed a commit to thomasantony/zola that referenced this pull request Sep 17, 2022
* rendering/markdown: fix shortcode handling in codefences

* rendering/tests: add a bunch of tests for codefence + shortcode usages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants