6

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. Commented Apr 21, 2016 at 11:50

2 Answers 2

6

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
  • 2
    As of Craft 3.5, the inlineOnly directive works with core too
    – Urs
    Commented Dec 13, 2020 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 and acknowledge you have read our privacy policy.

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