- How do I install spatie/laravel-markdown-blade-component in a Laravel app?
- Install it with Composer using composer require spatie/laravel-markdown-blade-component. The package ships a Laravel service provider and a Blade component, so auto-discovery handles registration and no manual wiring is required. Optionally publish the config file with php artisan vendor:publish to adjust rendering options. After that you can drop <x-markdown> into any Blade view.
- Does this package support GitHub-flavored Markdown like tables, task lists, and strikethrough?
- Yes. The component is built on league/commonmark and is configured for GitHub-flavored Markdown, which covers tables, task lists, strikethrough, autolinks, and fenced code blocks. You pass your Markdown as the component slot content and it comes back as HTML. If you need to trim the feature set, the enabled CommonMark extensions are controlled through the published config file.
- Is the HTML output safe for user-generated content, or is there an XSS risk?
- Markdown rendering is an XSS sink if raw HTML is allowed through and the output is not sanitized. The package exposes html_input-style configuration, and you should deliberately choose between escaping or stripping raw HTML and sanitizing the rendered output with an HTML purifier. If any Markdown comes from end users, treat that as a security policy decision that needs sign-off and test coverage before shipping. For trusted authors such as CMS editors, the default posture is usually acceptable.
- Do I need Node.js installed to use this package?
- Only if you want Shiki-powered syntax highlighting. Highlighting is delegated to Shiki through spatie/shiki-php, which shells out to a Node.js process at render time, so Node must exist on PATH and be executable by the PHP process in every environment including CI and containers. If Node is unavailable or you would rather avoid it, disable highlighting and the component still renders correct CommonMark HTML. That fallback makes the package usable in serverless or minimal container setups.
- How does caching work for rendered Markdown?
- The package includes a built-in render cache so repeated Markdown does not get re-parsed or re-highlighted on every request. Because it uses the standard Laravel cache repository, it inherits whatever store you already run, such as Redis, the database, or files. Be aware of cold-cache behavior and possible cache stampedes before exposing a high-traffic page, since spawning a Node process per uncached code block is noticeably more expensive than pure-PHP parsing. Caching can be configured or turned off in the config file.
- Which Laravel and PHP versions does this package support?
- The package targets modern Laravel on PHP 8.1 or newer, and it is Laravel-native in the sense that it registers a service provider, publishes config, and provides a Blade component. Release activity suggests ongoing maintenance, but you should always confirm the supported Laravel and PHP matrix against your own target versions before adopting. The hard parsing work lives in league/commonmark, so version constraints largely follow that dependency.
- How do I configure the component after installing it?
- Publish the package config with php artisan vendor:publish and select the markdown package's config file. From there you can control things like permitted raw HTML, enabled CommonMark extensions, syntax highlighting behavior, and caching. Because the component reads that config, changes apply to every <x-markdown> usage without touching your views. Keep the config under version control so environment differences are explicit.
- Can I render Markdown in places other than plain Blade views, like Livewire or Inertia apps?
- The package is a thin presentation layer, so it does not presume Livewire, Inertia, or any particular frontend framework. It renders server-side to HTML, which you can stream, store, or pass as a prop to a SPA. In Livewire you can use it anywhere Blade is compiled, including component views. For anything outside a Blade context, you would fall back to league/commonmark directly.
- How does it compare to alternatives like laravel-markdown or Parsedown-based packages?
- This package's differentiator is the Blade component wrapper plus Shiki-grade syntax highlighting and a built-in render cache, all on top of league/commonmark. Parsedown-based packages are lighter and pure PHP but typically give you weaker CommonMark compliance and no highlighting story. The trade-off here is the optional Node.js runtime in the request path, which pure-PHP alternatives avoid. If you do not need high-fidelity highlighting, a simpler package may be the cheaper choice.
- How should I test Markdown rendering in my application?
- Write feature or view tests that render the Blade component with representative content and assert on the resulting HTML, including fenced code blocks and any GitHub-flavored constructs you rely on. Add explicit tests for your XSS stance, such as attempts to inject scripts or event handler attributes through raw HTML in the Markdown. If highlighting is enabled, test in an environment that mirrors production, because missing Node is a common works-locally-breaks-in-CI failure. Also test cache behavior by rendering the same input twice.