- How do I integrate this package with Laravel’s Blade templates for Markdown rendering?
- Use the `@markdown` directive from `spatie/laravel-markdown` to render Markdown in Blade. The package automatically extends `league/commonmark` with Shiki syntax highlighting, so no extra configuration is needed beyond installing both packages. Ensure your Blade template includes the required CSS for Shiki’s output.
- What Laravel versions and PHP requirements does this package support?
- This package requires Laravel 8+ and PHP 8.0+ due to dependencies on `league/commonmark` (v1.0+) and `spatie/shiki-php`. Check the [README](https://github.com/spatie/commonmark-shiki-highlighter) for exact version constraints, as breaking changes may occur with major updates to these dependencies.
- Can I customize the syntax highlighting theme or language defaults?
- Yes, you can configure themes and language overrides via the CommonMark environment. For example, set a default theme like `'github-dark'` or override languages for specific code blocks. Refer to the `spatie/shiki-php` documentation for supported themes and languages.
- Will this package work with Antlers or other templating engines in Laravel?
- The package supports Antlers out of the box, as it extends `league/commonmark` directly. If you’re using Antlers, ensure your Markdown processor is configured to use the Shiki-highlighted renderer. For other templating engines, verify compatibility with `league/commonmark` first.
- How do I handle performance issues with large Markdown files or high traffic?
- Cache rendered Markdown output using Laravel’s caching system (e.g., `spatie/laravel-caching`) or a dedicated cache driver. Shiki PHP is fast, but heavy Markdown processing can impact latency. For static content, consider pre-rendering and storing HTML snippets.
- Are there alternatives if I don’t want to use Shiki for syntax highlighting?
- Yes, alternatives include client-side libraries like Prism.js or Highlight.js, which offload work to the browser. For server-side solutions, you could use `league/commonmark-extensions` or other syntax-highlighting packages like `vlucas/phpdox` (though they may lack Shiki’s language support).
- How do I handle unsupported languages or malformed Markdown in production?
- The package gracefully falls back to plain-text rendering for unsupported languages or malformed Markdown. Implement a fallback mechanism in your Markdown processor (e.g., wrap the renderer in a try-catch block) to ensure robustness. Test edge cases like nested code blocks or invalid syntax.
- Do I need to install the JavaScript Shiki package (`shiki`) for this to work?
- No, this package uses the PHP port of Shiki (`spatie/shiki-php`), so you don’t need the JavaScript version. However, ensure you install `spatie/shiki-php` via Composer (`composer require spatie/shiki-php`) as it’s a required dependency.
- Can I add custom languages or modify the highlighted output post-rendering?
- Yes, the package is extensible. You can register custom languages via `spatie/shiki-php` or post-process the HTML output with JavaScript (e.g., adding line numbers or copy buttons). Check the `spatie/shiki-php` docs for language registration and the CommonMark environment for renderer hooks.
- How do I test this package in a Laravel application before deploying to production?
- Test in a staging environment by processing sample Markdown files with code blocks in various languages. Use Laravel’s `Markdown` facade (from `spatie/laravel-markdown`) to render content and verify the output matches expectations. Check for CSS conflicts and edge cases like empty code blocks or unsupported syntax.