Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Commonmark Laravel Package

league/commonmark

Highly extensible PHP Markdown parser supporting full CommonMark and GitHub-Flavored Markdown. Convert Markdown to HTML with simple converters, customize rendering via extensions, and run safely with options like stripping HTML and blocking unsafe links.

View on GitHub
Deep Wiki
Context7

league/commonmark is a highly extensible PHP Markdown parser implementing the full CommonMark spec with optional GitHub-Flavored Markdown support. Designed for modern apps, it offers safe, configurable HTML output and a powerful extension system for custom syntax and rendering.

Use CommonMarkConverter or GithubFlavoredMarkdownConverter to quickly convert Markdown to HTML with fine-grained options.

  • Full CommonMark compliance + GFM support
  • Secure rendering controls (e.g., strip HTML, block unsafe links)
  • Rich extension architecture for custom blocks/inline parsing
  • Strong typing and quality tooling (Psalm, CI, coverage)
  • Built for PHP 7.4+ with mbstring
Frequently asked questions about Commonmark
How do I install league/commonmark in a Laravel project?
Run `composer require league/commonmark` in your project root. The package requires PHP 7.4+ and the `mbstring` extension. No additional Laravel-specific setup is needed for basic usage.
Can I use this package to render Markdown in Laravel Blade templates?
Yes, but you’ll need a wrapper (e.g., a Blade directive or a service provider). Pair it with a Twig/Blade extension like `aptoma/twig-markdown` for seamless integration in views.
Does league/commonmark support GitHub Flavored Markdown (GFM)?
Yes, use the `GithubFlavoredMarkdownConverter` class instead of `CommonMarkConverter` to enable GFM features like tables, task lists, and strikethrough.
How do I secure user-generated Markdown to prevent XSS attacks?
Configure the converter with `html_input => 'strip'` and `allow_unsafe_links => false`. This strips unsafe HTML and blocks external links by default.
What Laravel versions does league/commonmark officially support?
The package itself has no Laravel-specific dependencies, but it works with Laravel 8+ (PHP 7.4+). Test thoroughly if using older Laravel versions with PHP 7.4+.
Can I extend league/commonmark to add custom syntax (e.g., emoji or LaTeX)?
Yes, use the `Environment` and `Extension` interfaces to add custom extensions. The package includes examples for GFM and supports third-party extensions like `commonmark-ext-pygments-highlighter`.
How do I cache parsed Markdown in Laravel to improve performance?
Cache the HTML output using Laravel’s `cache()` facade. For example, store the result of `$converter->convert()` in a cache key tied to the Markdown content hash.
What are the alternatives to league/commonmark for Laravel Markdown parsing?
Alternatives include `parsedown/parsedown` (simpler but less extensible) or `graham-campbell/laravel-markdown` (a Laravel wrapper for league/commonmark). Choose based on your need for GFM or custom extensions.
Will upgrading league/commonmark break my custom extensions?
Minor updates may fix spec compliance issues, potentially altering HTML output. Major versions require testing, especially if you rely on undocumented behavior or custom AST transformations.
How do I integrate league/commonmark with Laravel’s service container?
Bind the converter as a singleton in a service provider: `$this->app->singleton(CommonMarkConverter::class, fn() => new CommonMarkConverter(['html_input' => 'strip']));`. Inject it into controllers or services via constructor.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport