If I want to switch from markdownify to .RenderString:
Where am I supposed to place .RenderString, on the templates’ .Content? then I can remove markdownify from the shortcodes’ .Inner?
When I do the above, I have some strange behavior compared to markdownify: some ULs are missing, some Ps are inserted inside LIs… any idea to fix that?
Is this the proper way to go if I want a “global approach” where all markup is parsed to Markdown? I tried to apply .RenderString directly from baseof.html to embrace everything (header, main block, footer…) but I didn’t manage to.
It took me a little tinkering until I learned that .RenderString must be called on the actual Page object and not the string itself, i.e. switching my shortcodes from {{ .Text | markdownify }} to {{ $.Page.RenderString .Text }}.
Haven’t used it on a template but it should be something similar, like {{ .Page.RenderString .Content }}? Trial and error always gets me there eventually
If you add options to the mix, I think it’s easier to reason about if you use the pipe syntax, e.g.
{{ .Text | $.Page.RenderString $options }}
And for people asking “why complicate stuff by needing the page context”, the answer is that the render hooks are very much tied to a Page (template lookups, the page context sent into the hooks etc.), so a stateless function will not work (as well).
In fact simply {{ .Content | .RenderString }} in template files seems to work, no need to markdownify shortcodes’ .Inner then, nor to use the % shortcode delimiters.
But it messes up my lists, wrapping LIs with <p> </p>, adding </DIV>s and so on, whereas it was fine with markdownify. Using the % shortcode delimiters also messes up.
Indentations in the shortcode seems to cause the problem (whereas it was kind of fine with markdownify).
I created a test for you to check locally: can you have a look?
Just clone my test branch on my website and go to /test.
Haha ok but I cannot make it work on templates otherwise: {{ $.Page.RenderString }} throws an error.
And the problem still occurs when only using % for shortcodes.
In the meantime I was wondering why the functionality of | .RenderString was not applied in .Content by default, which would remove the need to add it on every .Content of our templates…
Well it doesn’t work consistently.
Can we provide a guide to switch from {{ .Inner | markdownify }} (in shortcodes) to using .RenderString (in templates I guess but I’m not sure where else I could put it) in order to benefit from Render Hooks, and more generally about how to use .RenderString?
.RenderString is a method on Page
doesn’t seem to tell me how to use it properly (maybe because I am not really familiar with Go, yet I’ve been using and enjoying Hugo for years now).
.Content will already render the markup (mardkown image, links, shortcodes etc…). .RenderString has been introduced so that any string can be “rendered” and not only the body “content” of a content file.
So simply calling {{ .Content }} from your template files should have the expected effect of rendering the “Content” part of your markdown file (anyting below the Front Matter).