Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Pixelairport's avatar

Markdown for Blog Posts?

Hi. I started to move wordpress blog posts to laravel. I realized that wordpress makes some things to make html valid for browser, even if there are problems with html... like adding p tags ...

What I thought today, if it is better to give authors less options and use markdown. Not for landing pages or main pages like homepage. Only the real blog articles, which are about information. That would help the author to focus on the text and dont have so many problem, if i move to a new page or new design.

Last question. Is it possible in laravel to make markdown look special. Like when I have two images normally markdown would show the second under the first. That would also be in the next design. But could I make some blade helper that say, if there are two images right after another show the pictures left and the other right? Or that i can say, make first #headline bigger than other #headlines?

... This is just a topic I just think about. What do you prefer? At the moment I use CKEditor in Laravel. But I think that is also not a good idea for blog posts.

0 likes
2 replies
LaryAI's avatar
Level 58

Using Markdown for blog posts is a good idea as it simplifies the process for authors and ensures valid HTML. Laravel has built-in support for Markdown through the Parsedown library. You can use it to parse Markdown content and convert it to HTML. To make Markdown look special, you can create custom Blade directives that apply specific styles to certain elements. For example, you can create a directive that applies a float: left style to the second image if it immediately follows the first image. Here's an example of how to use Parsedown in Laravel:

// In your controller
use Parsedown;

public function show($id)
{
    $post = Post::find($id);
    $parsedown = new Parsedown();
    $content = $parsedown->text($post->content);
    return view('posts.show', compact('post', 'content'));
}

// In your view
{!! $content !!}

To create a custom Blade directive, you can use the Blade::directive method. Here's an example of a directive that applies a float: left style to the second image if it immediately follows the first image:

// In your AppServiceProvider boot method
use Illuminate\Support\Facades\Blade;

Blade::directive('floatImages', function ($content) {
    return preg_replace('/(<img.*?>)\s*(<img.*?>)/', '<div style="float: left"></div>', $content);
});

// In your view
@floatImages($content)
Pixelairport's avatar

Parsedown works, but is there a way now to rewrite the code while parsing? I mean can I say:

# Headline ... will become <h1 class="blogHeadline"> instead of only <h1>

or can i do some things like every first headline is red. Or when I have one image following another the second is float right? I dont want to use something like @floatImage([https://myimage.jpg]) in my markdown. I want to have clean markdown, that we also could move it to another page and it looks good.

Please or to participate in this conversation.