Auto markdownify all capture blocks?

Hello everyone!

I’m making a site which I’d like to make multilingual, but the page structure is complicated so of course I’ll not just duplicate the page for each language, so after long researches I found I could use capture with include, so here’s what I ended with.

The problem is that Markdown isn’t rendered. I also saw I could use | markdownify to forcefully render it, but if I have to put it around all sections this will quickly become redundant.

Thanks for your help!

Thanks for the link. I’m still not sure of what you’re doing.

There is a multi lingual plugin I think.

Also you can store your data in frontmatter so you don’t need capture. Then then use markdownify on fields.

en/index.md

---
section_a:
  heading: Good morning
  content: |
     How are _you_?

     **Goodbye**

     ### Here is a level 3 heading

     More content.

section_b:
  heading: ...
  content: ...
---

## {{ page.section_a.heading }}

{{ page.section_a.content | markdownify }}

## {{ page.section_b.heading }}

{{ page.section_b.content | markdownify }}


You could break that main part of the page into an includes file. Which will have access to page data even.

en/index.md

---
section_a: ...
section_b: ...
---

{% include my-include.html %}

_layouts/my-include.html

<h2>{{ page.section_a.heading }}</h2>

{{ page.section_a.content | markdownify }}

<h2>{{ page.section_b.heading }}</h2>

{{ page.section_b.content | markdownify }}

(BTW markdownify wraps the content in a p tag. And will not render Liquid.)

But then you have to repeat use of include on two translated pages which is not so nice. So I would keep the content of the pages empty after the frontmatter and then use a layout to insert the content.
Then two index.md pages in different languages can share a layout. And if you run the risk of a layout for every single page, then make your layout support any page. Things like headings and content and reusable across pages and you can use an array and for loop if you want some pages to have say 10 sections without having to repeat blocks of content 10 times in your layout.


I’ve seen a pattern before of setting up in layouts. Will this work? Instead of capture.

In page.html or default.html layout

<body>
  {{ content | markdownify }}
</body>

Here’s another example, closer to your gist. I left out the heading fields and left that up to the index pages.

_includes/my-test.html

<section>
  {{ page.first_section | markdownify }}
</section>
<section>
  {{ page.second_section | markdownify }}
</section>

en/index.md

---
first_section: |
  # First section

  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec elementum tempor urna, id volutpat nisl tincidunt eu. Integer sit amet est ex. Suspendisse non tortor purus. Vivamus quis nisl purus. 

  Phasellus non lorem vitae dui maximus tempus. Donec sollicitudin vestibulum leo sed egestas.

second_section: |
  # Second section

  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec elementum tempor urna, id volutpat nisl tincidunt eu. Integer sit amet est ex. Suspendisse non tortor purus. Vivamus quis nisl purus. Phasellus non lorem vitae dui maximus tempus. Donec sollicitudin vestibulum leo sed egestas.
---

{% include my-test.html %}


PS if you have trouble keeping your empty lines in the output, you can look up YAML syntax to preserve the empty lines. See Block Scalars here.

And you can use this to turn newline in markdown into HTML br tags. I don’t know if you’ll need it at all if you use markdownify. Or if it needs to with markdownify.

{{ my_text | newline_to_br }}

That’s what I need, thanks, sorry for the late answer

1 Like