-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[10.x] Markdown engine #49455
[10.x] Markdown engine #49455
Conversation
This is a breaking change to put into Laravel 10, and indeed breaks my package which registered a markdown renderer. |
Hm, I just looked at your package and won’t your engine registration just override the default? I’m on my phone so I can’t really check, but it sure seems like your package would just replace this… |
@GrahamCampbell this isn't a breaking change. But if it breaks your package we could maybe re-consider it for Laravel v11. Let's see what @taylorotwell says. |
FWIW I just created a new Laravel project, swapped in this fork, installed |
I'm not sure I want to take on any opinions on what a Markdown view engine should look like. I would rather leave it to packages. For example, I could imagine people might want to use Blade syntax within Markdown to potentially echo variables or use control structures, which could easily be done now via something like: return Str::markdown((string) view('some.view-that-contains-markdown', $data)); |
@taylorotwell I get it. That said, my one take would be: this was intentionally implemented very minimally and with zero opinions. In all of the recent Laravel projects I've worked on, I've needed markdown views. I know the Laravel docs implement this. I know the Verbs and Livewire docs also both implement this. It feels to me that a simple, but extensible markdown view engine would be great for many people. I also definitely planned on PR'ing |
I think it's best left outside the framework core tbh. May people have opinionated ways to do this. |
|
This introduces a new view engine for rendering markdown files. It allows you to add
.md
files to yourviews/
directory and render them like any other view:If you want to wrap markdown in a layout or manipulate it in some way, you can register a callback:
(This callback receives the rendered HTML, the CommonMark
RenderedContentInterface
instance, the data passed to the view, and the path of the markdown file being rendered.)Personally, I would love to add a
renderMarkdownUsing
method to theView\Factory
that handled the engine resolution for you, but I wanted to keep this PR as focussed as possible.By default, the markdown engine will use the
GithubFlavoredMarkdownConverter
(which is the default in existing Laravel markdown implementations), but you can bind anyLeague\CommonMark\ConverterInterface
interface to the container to make that the default: