Jekyll - How can I make avoid a paragraph to be added on a YAML frontmatter markdownify item Jekyll - How can I make avoid a paragraph to be added on a YAML frontmatter markdownify item ruby ruby

Jekyll - How can I make avoid a paragraph to be added on a YAML frontmatter markdownify item


You can use the remove filter like this :

{{ host | markdownify | remove: '<p>' | remove: '</p>' }}


Well... It's quite old question, but still actual.

You can use | remove: '<p>' | remove: '</p>' like David Jacquel answered before. But it will remove every <p> tag in the text.

But if you want to remove <p>-tag wrapping only in cases there is only one <p> node, you'll need more complex solution.

There are few ways to do that without external plugins and filters.

And this is my solution:

{%- assign arr = yourTextVar | markdownify | strip | split: "<p>" -%}{%- if arr.size > 2 -%}  {{ arr | join: "<p>" | prepend: "<p>" }}{%- else -%}  {{ arr[1] | remove: "</p>" }}{%- endif -%}

It'll split the text on empty <p> tag and will ignore anything like <p id="my-id">


use md.renderInline() to remove the <p> tag