Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include a HTML file inside a markdown file in jekyll?

I have a jekyll site with filestructure like so:

▾ _includes/
    post-entry.html
▾ _posts/
    2012-11-25-first-post.markdown
index.markdown

In my index.markdown, I want to include a post-entry.html like this:

{% for post in site.posts %}
* {% include post-entry.html %}
{% endfor %}

But this appears as a HTML code snippet in the blog. How can i prevent the HTML from being protected?

like image 444
SiddharthaRT Avatar asked Nov 25 '12 09:11

SiddharthaRT


People also ask

Can I include HTML in Markdown?

Span-level HTML tags — e.g. <span> , <cite> , or <del> — can be used anywhere in a Markdown paragraph, list item, or header. If you want, you can even use HTML tags instead of Markdown formatting; e.g. if you'd prefer to use HTML <a> or <img> tags instead of Markdown's link or image syntax, go right ahead.

Can I use HTML in Jekyll?

Your Jekyll pages consist of HTML, CSS, and JavaScript, so pretty much any code you need to embed will work without a problem.

How do I add HTML to MD?

You can add html inside markdown files in /content. However your indented code will follow markdown formatting. You could also save your content files as . html but then you'll have to write everything in html.


2 Answers

You can use liquid tags in any markdown file so long as it has YAML header matter. For instance, check out the index.md given in the jekyllbootstrap template for Jekyll sites.

If you link to your actual index.markdown or your repository itself (e.g. if it's on github), we could probably get a better idea of what has gone wrong. Your example should work, though you might need to use HTML list element <li> rather than the markdown *.

like image 198
cboettig Avatar answered Sep 28 '22 09:09

cboettig


The problem is the parser views the HTML as code blocks. The best way would be to turn off code blocks like I asked in this question

To work around use the replace tag:

{% capture includeGuts %}
{% include post-entry.html %} 
{% endcapture %}
{{ includeGuts | replace: '    ', ''}}
like image 39
David Silva Smith Avatar answered Sep 28 '22 11:09

David Silva Smith