# Rendering Markdown inside an html include

**URL:** <https://talk.jekyllrb.com/t/rendering-markdown-inside-an-html-include/4186>\
**Category:** Help\
**Created:** [April 4, 2020, 5:54am UTC](https://talk.jekyllrb.com/t/rendering-markdown-inside-an-html-include/4186 "2020-04-04T05:54:40Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![KhBh](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/khbh/32/4845_2.png) [@KhBh](https://talk.jekyllrb.com/u/KhBh)\
**Post date:** [April 4, 2020, 5:54am UTC](https://talk.jekyllrb.com/t/rendering-markdown-inside-an-html-include/4186/1 "2020-04-04T05:54:40Z")

</div>

Hello fellow Jekyllers!

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?

In case you want to see, [here is a page on my site exhibiting the problem](https://buddhist-uni.github.io/authors/white-curtis) (note the raw `> quote` inside the box) and [here is the relevant include file](https://github.com/buddhist-uni/buddhist-uni.github.io/blob/7f734d06f0d64861df3dae9df290f5cc3ac99e73/_includes/highlighted_content.html).

Oddly, it seems to only be a problem with that particular include. A e.g. `{{ post.excerpt }}` in other includes render markdown just fine 😕

Any help understanding what’s going on here would be appreciated, thanks!

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [April 4, 2020, 9:43am UTC](https://talk.jekyllrb.com/t/rendering-markdown-inside-an-html-include/4186/2 "2020-04-04T09:43:33Z")

</div>

Hi @KhBh

One approach could be to use `markdownify` filter to convert markdown to rendered HTML.

> **[Liquid Filters](https://jekyllrb.com/docs/liquid/filters/)**
>
> All of the standard Liquid filters are supported (see below).

```auto
{{ include.content.content | markdownify }}

```

Don’t use markdown=“block”

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [April 4, 2020, 9:52am UTC](https://talk.jekyllrb.com/t/rendering-markdown-inside-an-html-include/4186/3 "2020-04-04T09:52:45Z")

</div>

Here’s another approach. I recently added markdown to my includes file.

The includes file ends in `.md` and I just use markdown code. [\_includes/link\_list.md](https://github.com/MichaelCurrin/coding-blog/blob/master/_includes/link_list.md)

```auto
{% for link in page.links %}
- [{{ link.title }}]({{ link.url }})
{% if link.description %} - {{ link.description }}{% endif %}
{% endfor %}

```

And it renders here - [blog post](https://michaelcurrin.github.io/coding-blog/2020/04/02/links.html)

## Further notes

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:

```nohighlight
<div>

- This text WILL render as markdown bullet point.

</div>

```

Result:

- This text WILL render as markdown bullet point.

### No empty lines

Code:

```nohighlight
<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:**

```nohighlight
<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.

```

---

<div class="post-metadata">

**Author:** ![KhBh](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/khbh/32/4845_2.png) [@KhBh](https://talk.jekyllrb.com/u/KhBh)\
**Post date:** [April 4, 2020, 10:07am UTC](https://talk.jekyllrb.com/t/rendering-markdown-inside-an-html-include/4186/4 "2020-04-04T10:07:08Z")

</div>

Thanks! ` | markdownify` did the trick!

But I’m still a bit confused, why did I _not_ need to `markdownify` in [my other, very similar, include](https://github.com/buddhist-uni/buddhist-uni.github.io/blob/7f734d06f0d64861df3dae9df290f5cc3ac99e73/_includes/content_box.html)?

---

<div class="post-metadata">

**Author:** ![michaelbach](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelbach/32/2151_2.png) [@michaelbach](https://talk.jekyllrb.com/u/michaelbach)\
**Post date:** [April 6, 2020, 6:49am UTC](https://talk.jekyllrb.com/t/rendering-markdown-inside-an-html-include/4186/5 "2020-04-06T06:49:08Z")

</div>

possibly because it’s an `html`, not `md` file?

---

<div class="post-metadata">

**Author:** ![KhBh](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/khbh/32/4845_2.png) [@KhBh](https://talk.jekyllrb.com/u/KhBh)\
**Post date:** [April 6, 2020, 7:33am UTC](https://talk.jekyllrb.com/t/rendering-markdown-inside-an-html-include/4186/6 "2020-04-06T07:33:23Z")

</div>

Yeah, I thought that too, so I tried changing [the `_layout` file](https://github.com/buddhist-uni/buddhist-uni.github.io/blob/master/_layouts/author.md) 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`?

---

<div class="post-metadata">

**Author:** ![michaelbach](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelbach/32/2151_2.png) [@michaelbach](https://talk.jekyllrb.com/u/michaelbach)\
**Post date:** [April 6, 2020, 7:56am UTC](https://talk.jekyllrb.com/t/rendering-markdown-inside-an-html-include/4186/7 "2020-04-06T07:56:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![KhBh](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/khbh/32/4845_2.png) [@KhBh](https://talk.jekyllrb.com/u/KhBh)\
**Post date:** [April 6, 2020, 8:20am UTC](https://talk.jekyllrb.com/t/rendering-markdown-inside-an-html-include/4186/8 "2020-04-06T08:20:28Z")

</div>

So I did a little more reading of the Jekyll docs, and [the order of interpretation page](https://jekyllrb.com/tutorials/orderofinterpretation/) 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! 🙂

---

<div class="post-metadata">

**Author:** ![michaelbach](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelbach/32/2151_2.png) [@michaelbach](https://talk.jekyllrb.com/u/michaelbach)\
**Post date:** [April 7, 2020, 5:57am UTC](https://talk.jekyllrb.com/t/rendering-markdown-inside-an-html-include/4186/9 "2020-04-07T05:57:34Z")

</div>

Thank you for pointing to the doc page. Much clearer now. M.

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [April 9, 2020, 8:46pm UTC](https://talk.jekyllrb.com/t/rendering-markdown-inside-an-html-include/4186/10 "2020-04-09T20:46:12Z")

</div>

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.

# HTML includes test:

`_includes/a.html`

```auto
<ul>
    <li>
        Plain: {{ include.foo }}
    </li>
    <li>
        Markdownify: {{ include.foo | markdownify }}
    </li>
</ul>

```

Usage in index.md

```auto
## a.html

{% include a.html foo='[github](https://github.com)' %}

```

Rendered result (HTML copy and pasted here, renders in the forum as it did on my Jekyll local page)

## a.html

- Plain: [github](https://github.com) 
- github

Note the first point treated as plain text and the second gets rendered used markdownify.

# Markdown includes:

`_includes/b.md`

```auto
- Plain: {{ include.foo }}

- Markdownify: {{ include.foo | markdownify }}

```

Usage in index.md

```auto
## b.md

{% include b.md foo='[github](https://github.com)' %}

```

Here is how that renders (copy pasted HTML)

## b.md
 
- Plain: github
- Markdownify: \<p\>github\</p\>

Note the used of markdownify in markdown file works well in the first point. In the second point, the double markdown adds `&lt;p&gt;` for `<p>` tag.
