Parse YAML entries as Markdown?

Hello,

I am trying to use liquid tags to parse YAML entries and print those entries nicely on a page in Jekyll. I plan to use a ‘news’ file with the following format:

news1:
  date: 2018-07-01
  note: News item

news2:
  date: 2018-11-18
  note: News item with a link to American Physical Society's [Division of Fluid Dynamics](https://www.aps.org/units/dfd/) and some _italic text_.

I put the above inside a file at _data/news.yml and then I have the following page in my site:

---
layout: page
title: test
permalink: /test/
nav: true
---
{% if site.data.news %}
    {% assign newslist = site.data.news %}
    {% for entry in newslist %}
      {% assign key = entry | first %}
        Date: {{ newslist[key].date}} 
        Content: {{ newslist[key].note }}
    {% endfor %}
{% endif %}

This correctly loops through each entry in the yaml file and prints the “date” and “note” entries. However, it does not render them nicely as Markdown, it just renders them as monospaced text, as if it were a code block. Thus, italics and links are lost and it just doesn’t look very nice.

I have tried to use the || markdownify as per this answer, and also tried enclosing my entries inside <article> ... </article>, but this hasn’t helped.

What’s the file type/extension of your test page? If it is Markdown (.md), then you have to be very careful with white-space indentation. In Markdown, a line that starts with a tab or 4+ spaces is interpreted as a code block.

Try removing all the indentation from your if/for Liquid code.

Thanks! That’s what it was. I removed all indentation and added || markdownify.

1 Like