Laravel 8: Markdown editor does not seem to be working

202
April 08, 2021, at 4:10 PM

I'm working with Laravel 8 to make an Online Forum and in this project, I used this package which is a Markdown Editor for questions that come with codes.

So I ran composer require michelf/php-markdown and after installation completed, I tried to use it by saying:

<div class="thread-details">
    {!! \Michelf\Markdown::defaultTransform($thread->thread)  !!}
</div>

But now the problem is, it returns nothing as output!

So how can I fix this issue?

I would really appreciate if you share any idea or suggestion about this with me...

Thanks in advance.

Answer 1

Enable autoloading .. What i did was i ran

composer require michelf/php-markdown

Then in vendor/composer/autoload_psr4.php i included...

return array(
...
    'Michelf\\' => array($vendorDir.'/michelf/php-markdown/Michelf'),
);

Then inside controller

  <?php
    
    namespace App\Http\Controllers;
    use Michelf\Markdown;
    use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
    use Illuminate\Foundation\Bus\DispatchesJobs;
    use Illuminate\Foundation\Validation\ValidatesRequests;
    use Illuminate\Routing\Controller as BaseController;
    class ListController extends Controller
    {
    public function index (){
            $my_html = Markdown::defaultTransform('*normal emphasis with asterisks*');
        
        $my_html1 = Markdown::defaultTransform('_normal emphasis with underscore_');       
        $my_html2 = Markdown::defaultTransform('**strong emphasis with asterisks**');
        $my_html3 = Markdown::defaultTransform('__strong emphasis with underscore__');
        $my_html4 = Markdown::defaultTransform('This is some text *emphased* with asterisks.');
        echo $my_html;
        echo $my_html1;
        echo $my_html2;
        echo $my_html3;
        echo $my_html4;
    }
    }

In web.php

<?php
use App\Http\Controllers\ListController;
use Illuminate\Support\Facades\Route;
Route::get('/markdown',[ListController::class,'index']);

Then i ran php artisan serve

and i got...

READ ALSO
Salesforce - How to scan QR Code in a PDF file?

Salesforce - How to scan QR Code in a PDF file?

I need to scan a QR code in a PDF fileThis code can be anywhere in the document, position is not fixed

211
extract string between two keywords spanning multiple lines using nodejs

extract string between two keywords spanning multiple lines using nodejs

I have been trying to parse typescript files to extract imports from a typescript component file using nodejs, but got stuck at the point where the imports are listed on multiple linesfor e

102
Get HTML from Vuetify components without posting it on the dom

Get HTML from Vuetify components without posting it on the dom

For my own project I would like to fetch HTML code from multiple Vuetify componentsNot as a HTML string, but really as a DOM element that can immediately be appended to the body

27
Replacing nested loops in Python using NumPy

Replacing nested loops in Python using NumPy

So I have these 6 nested loops, and their purpose is only to multiply and add arrays X and Y over different indices to get array Z

102