I am trying (and failing, in this case) to render Markdown inside an html “include.” I tried putting markdown="block" on the div to no avail. What else should I try?
If you are going to mix HTML tags and markdown, make sure you leave open lines, as demonstrated below. And also do not indent the markdown code simply for readability - otherwise it will turn into code blocks.
The behavior here below on this forum matches what you get in Github. Where I have used bullet point here, you could equally use > for quote.
Good
Code:
<div>
- This text WILL render as markdown bullet point.
</div>
Result:
This text WILL render as markdown bullet point.
No empty lines
Code:
<div>
- This text will NOT render as markdown bullet point but as plain text.
</div>
Result:
- This text will NOT render as markdown bullet point but as plain text.
Bad indentation
Code:
<div>
- This text is indented 4 spaces so will become a code block and NOT a bullet point.
</div>
Result:
- This text is indented 4 spaces so will become a code block and NOT a bullet point.
Yeah, I thought that too, so I tried changing the _layout file to .md but that didn’t work. I guess there is some Jekyll internal logic which always treats _layout files as html even if you name them .md?
Ah, I had not considered it’s a file in the _layouts directory, learned something new again. I am not sufficiently fluent in Jekyll to comment on your convincing “some Jekyll internal logic” comment.
Best, Michael.
So I did a little more reading of the Jekyll docs, and the order of interpretation page suggests that, indeed, markdown to html conversion is completed before_layout templates are applied, making any markdown in a layout file moot. Not at a computer right now to verify this, but it makes sense of the behavior I was seeing. Thanks for your help everyone!
Markdownify filter aside - yes a layout file can indeed be .md, as per the Coding Blog link I posted for an includes file and a live page using that. Just make sure you stop and start the server so it can reload the includes.
I did some testing - with regards to markdownify.
That works well inside .html layout - the markdown would not get rendered as HTML otherwise. It is unneeded inside an .md layout - if you use it you’ll rendered the markdown twice and get literal paragraph tag. See notes below.