radiate-framework / framework

A WordPress plugin and theme framework
https://radiate-framework.github.io/
MIT License
4 stars 0 forks source link

A markdown converter method on the View class #136

Closed BenRutlandWeb closed 2 years ago

BenRutlandWeb commented 2 years ago

Is your feature request related to a problem? Please describe. I want to be able to write documents in markdown and convert them to HTML

Describe the solution you'd like A markdown method on the View facade:

<?php
use Radiate\Support\Facades\View;

$title = 'Hello World';

echo View::markdown('posts.hello-world', compact('title'));

This would get the view and parse it from markdown into HTML.

Describe alternatives you've considered Wrapping the view call in a Str::markdown() method.

Additional context Adding the Macroable trait to the View Factory would enable me to do this myself if the use case isn't great.

BenRutlandWeb commented 2 years ago

The Macroable trait is added to the factory and view, so you can use this macro:

<?php

use Radiate\View\View;

View::macro('markdown', function () {
    return Str::markdown($this);
});

...and then...

<?php

use Radiate\Support\Facades\View;

$title = 'Hello World';

echo View::make('posts.hello-world', compact('title'))->markdown();

Or you can pass the rendered view to the markdown method.

The reason I won't add this is because it would no longer return the View instance, rather than a string. If additional methods are added to the view class, they won't be available on this method - think for example of translations.