5

Is there a way to parse a line of Markdown within Twig – without the surrounding <p> tags?

I see there is a StringHelper method called ParseMarkdownLine that does exactly what I'd like, but I haven't found a way to invoke it in my templates.

1
  • 1
    {{ item | markdown | replace('<p>','') | replace('</p>','') | raw }} works for a single line, but it does not feel right. – Avant la lettre Apr 21 '16 at 11:50
5

If you're here looking for a Craft 3 answer, the Wordsmith plugin offers the same ability to only parse inline and not include paragraph tags:

{{ entry.title|markdown(inlineOnly=true) }}
1
  • 1
    As of Craft 3.5, the inlineOnly directive works with core too – Urs Dec 13 '20 at 14:27
6

Have a look at the Parsedown plugin by P&T, it provides a line mode to not output any wrapping <p> tags.

{{ entry.title|parsedown('line') }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.