Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Markdown before parsing blade syntax? #67

Closed
unnawut opened this issue Dec 12, 2016 · 6 comments
Closed

Parse Markdown before parsing blade syntax? #67

unnawut opened this issue Dec 12, 2016 · 6 comments

Comments

@unnawut
Copy link

unnawut commented Dec 12, 2016

In BladeMarkdownEngine::get() the code is as follow:

public function get($path, array $data = [])
{
    $contents = parent::get($path, $data);

    return $this->markdown->convertToHtml($contents);
}

My .md.blade.php contains @extends('layouts.default'). This means that parent::get() has already parsed my blade template and puts loads of HTML into $contents.

When convertToHtml(), which supposed to get only Markdown syntax, gets the fully parsed HTML above, it goes crazy and hence lots of <pre><code> produced.

Is it possible to specify that markdown content in .md.blade.php should be parsed before parsing the rest of blade syntax in that file? If it's not already supported would you welcome a PR that allows that?

@GrahamCampbell
Copy link
Owner

We don't do this because blade syntax itself could be recognised by mistake as markdown, and thus, the file broken.

@unnawut
Copy link
Author

unnawut commented Dec 12, 2016

Right, I see. I'll see if I could make a blade syntax e.g. @markdown @endmarkdown instead.

@GrahamCampbell
Copy link
Owner

That would work for sure. Would be pretty easy to implement.

@GrahamCampbell
Copy link
Owner

Hmm, well, actually, not quite. Only if there was no other blade in between those annotations.

@GrahamCampbell
Copy link
Owner

Instead, I'd recommend moving your markdown parts to separate .md.blade.php file, then including that from a .blade.php file.

@unnawut
Copy link
Author

unnawut commented Dec 13, 2016

Just in case anyone wants to reference this. Here is what I ended up implementing (as @GrahamCampbell suggested). I'm specifically doing this for a release notes page but aiming to reuse the code for other static markdown pages in the future as well, hence the structure...

routes.php:

Route::controller('pages', 'MarkdownPagesController');

MarkdownPagesController.php:

<?php

class MarkdownPagesController extends \App\Http\Controllers\Controller
{
    public function getReleaseNotes()
    {
        return $this->markdownView('pages.release-notes');
    }

    protected function markdownView($markdownViewName)
    {
        return view('layouts.markdown', [
            'markdownViewName' => $markdownViewName,
        ]);
    }
}

views/layouts/markdown.blade.php:

<h1>Default content here</h1>

<div>
    @include($markdownViewName)
</div>

views/pages/release-notes.md:

## My markdown content

The code above generates a page like this for http://localhost/pages/release-notes:

<h1>Default content here</h1>

<div>
    <h2>My markdown content</h2>
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants