I'm not sure if it will work, but you can try the new Blade::doubleEncode() method. This should escape all special characters and replace them with the html equivalents.
Ref.: https://laravel-news.com/blade-double-encoding-vue-components
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi there,
I am sending some emails with the help of the markdown templates Laravel supplies by default. And I pass some variables to it. But because the content is parsed as markdown all parsedown characters like # __ * 1. > will be parsed too and can possibly mess up the email.
So the quesiton is. How should I handle this? I do not see any escape_markdown() or whatever method. And I can't seem to find a library that does this. I can play a little bit with str_replace(['#'],['\#'], $string); but I have a feeling there must be an easier way (read as: somebody already figured this out)
To give an example
template
# Heading 1
Some text here ... etc. etc. etc.
{{ $someVariable }}
If $someVariable starts with a # it will be rendered as a heading.
You could also try the method described in this SO question, and that is to put it in an html tag. Supposedly markdown within html tags won't get parsed as markdown. I suppose it's really up to whatever markdown parser laravel is using but it should be a quick test. So maybe just put it in a <div>{{ $textWithMarkdown }}</div>?
Please or to participate in this conversation.