cobalt.rs
cobalt.rs copied to clipboard
Include Markdown in Liquid templates
It would be useful to be able to include markdown in a liquid template file. If you try that now, the raw markdown will be copied over instead of compiling it.
@epage had a cool idea over in the chatroom:
{markdown}
List
- a
- b
- c
{endmarkdown}
inside the liquid file would trigger the stuff in between to be compiled to html, which would mean that
<random>
{markdown}
{include file.md}
{endmarkdown}
</random>
should then also work.
Use case
A little background on that: I'm currently trying to move to something built on cobalt (who would have guessed) and html5up.net/hyperspace. I prefer having the actual content in md instead of html, so I'm trying to replace all the demo content from there with includes to my markdown files, which doesn't work because of the issue above
The main problem is that its not like some html, then a block of content and then some more html, but a lot of formatting with divs, classes and stuff, with content in sections between that
Workarounds that failed:
- Top-level file determines if includes are treated as markdown or not, so switch those to markdown and include in them what html you need (since markdown lets some html pass through)
- Didn't work: markdown didn't pass it along
- Make the top-level file markdown and put all the complex html into a layout
- Didn't work: content is too intermixed
One idea is to parse an include as markdown based on its extension. My concerns with that
-
top -> middle -> bottom
. If each layer is a different format, we'd need some kind of way to track when to process an include as markdown or not.
This is what then led to the idea of the {markdown}
block.
In jekyll its possbile to do that with markdown="block"
attribute ( from Kramdown
):
The markdown attribute: If an HTML tag has an attribute
markdown="0"
, then the tag is parsed as raw HTML block. If an HTML tag has an attributemarkdown="1"
, then the default mechanism for parsing syntax in this tag is used. If an HTML tag has an attributemarkdown="block"
, then the content of the tag is parsed as block level elements. If an HTML tag has an attributemarkdown="span"
, then the content of the tag is parsed as span level elements.
I wonder if someone has implemented it in Rust