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

Markdown inside shortcodes not processed with twig |markdown filter #59

Closed
jlehtinen opened this issue Jan 18, 2019 · 3 comments
Closed
Labels

Comments

@jlehtinen
Copy link

I wonder if this is a Grav or a Shortcode issue or expected behavior, or if this issue is related, but I'll describe the scenario:

I need to do some parsing to the page content before rendering in markdown, so:

  • I've disabled markdown in the frontmatter
  • then I do some content splitting and parsing in twig in the template
  • and then finally render the split parts using twig |markdown filter

Problem is that, even with markdown extra, content inside shortcodes (such as [div]…[/div]) then won't get rendered in markdown.

I've tried newlines etc., but at the moment the workaround looks like this:

---
process:
  markdown: false
---

[div]{{"

### Markdown content here

I'm an ugly workaround

"|markdown}}[/div]

…which works, but defeats the purpose of the exercise, which is to create complex long-pagers with a single, minimal markdown document with unobtrusive section dividers, a bit like the example in the docs where you render content separated by ---'s in columns, but I'm adding some parsing to throw some id's/classes in, too.

@jlehtinen
Copy link
Author

Template at its most basic of course looks like this…

{{ page.content|markdown }}

@rhukster
Copy link
Member

rhukster commented Feb 1, 2019

The fundamental problem here is that by using the markdown filter, you are doing that manually in Twig, and that means you are doing it after the shortcodes have run.

You really need to do any markdown processing first while the shortcode tags are still in the content, because markdown will not process any syntax between HTML tags.

Your approach is to do the shortcodes first (on content), and then try to process markdown, which is resulting in the the markdown between those html

tags the shortcodes have rendered, which won't work.

@jlehtinen
Copy link
Author

Thanks for the clarification. I realized that markdown=“1” will solve the problem in a satisfactory manner. I really need to do parsing this complex in a plugin with php instead of inside the template with twig, but there’s some learning I need to do first.

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

No branches or pull requests

2 participants