rmaicle

Programming is an endless loop; it's either you break or exit.

Licensed under a Creative Commons Attribution-ShareAlike 4.0 International License (CC BY-SA).
You are free to copy, reproduce, distribute, display, and make adaptations but you must provide proper attribution. Visit https://creativecommons.org/ or send an email to info@creativecommons.org for more information about the License.

markdownify Workaround

Date: 2017-04-20 13:38:32 +0000

Jekyll template filter markdownify is used to convert a markdown-formatted text into HTML. The example used in the Jekyll website is:

{{ page.excerpt | markdownify }}

Simple, right? I thought so too. What it did not mention is that markdownify wraps the source text within a <p> element. So that the result of the above code where the page.excerpt text for example is excerpt text:

<p>excerpt text</p>

I had created my template .html file usually wrapping YAML keys within HTML elements like the following code and was surprised at what I got. The above code was converted to (Jekyll 3.4.3 and github-pages 134):

<p class="excerpt"></p>
<p>excerpt text</p>

I posted the issue I encountered in irc #jekyll but got no response maybe because of my timezone. I needed a workaround to finish updating my GitHub Pages site.

The following code shows the simplest and fastest workaround I did.

{% assign excerpt = page.excerpt | markdownify | replace: '<p>', '' | replace: '</p>', '' %}
{{ excerpt | markdownify }}

Which produced the following output:

<p class="excerpt">excerpt text</p>
  •  markdownify