mozex/commonmark-routes
Composer 安装命令:
composer require mozex/commonmark-routes
包简介
A CommonMark extension that lets you use Laravel's route(), url(), and asset() helpers in Markdown links and images.
关键字:
README 文档
README
A league/commonmark extension that lets you use route(), url(), and asset() inside your Markdown content. Write links and images using the same Laravel helpers you already use in Blade, and they'll resolve to real URLs when the Markdown is converted.
Read the full documentation at mozex.dev: searchable docs, version requirements, detailed changelog, and more.
Warning: This extension evaluates helper calls from the Markdown source. Only use it with trusted content that you control. Don't process user-submitted Markdown with this extension.
Table of Contents
Support This Project
I maintain this package along with several other open-source PHP packages used by thousands of developers every day.
If my packages save you time or help your business, consider sponsoring my work on GitHub Sponsors. Your support lets me keep these packages updated, respond to issues quickly, and ship new features.
Business sponsors get logo placement in package READMEs. See sponsorship tiers →
Installation
Requires PHP 8.2+ - see all version requirements
Install the package via Composer:
composer require mozex/commonmark-routes
Usage
Register the extension with your CommonMark environment, then use route(), url(), or asset() in place of URLs in your Markdown.
use League\CommonMark\CommonMarkConverter; use Mozex\CommonMarkRoutes\RoutesExtension; $converter = new CommonMarkConverter(); $converter->getEnvironment()->addExtension(new RoutesExtension());
Links
The route() helper works exactly the way it does in your PHP code. Named routes, parameters, query strings, relative URLs:
echo $converter->convert("[Home](route('home'))"); // <p><a href="https://domain.com">Home</a></p> echo $converter->convert("[Product](route('product', 3))"); // <p><a href="https://domain.com/product/3">Product</a></p> echo $converter->convert("[Features](route('home', ['id' => 'features']))"); // <p><a href="https://domain.com?id=features">Features</a></p> echo $converter->convert("[Home](route('home', absolute: false))"); // <p><a href="/">Home</a></p>
The url() helper generates URLs from plain paths:
echo $converter->convert("[About](url('about'))"); // <p><a href="https://domain.com/about">About</a></p> echo $converter->convert("[Docs](url('docs/getting-started'))"); // <p><a href="https://domain.com/docs/getting-started">Docs</a></p>
The asset() helper resolves static file paths through Laravel's asset pipeline. This is especially useful in environments like Laravel Vapor where assets are served from S3 or CloudFront and relative paths won't work:
echo $converter->convert("[Download PDF](asset('files/doc.pdf'))"); // <p><a href="https://domain.com/files/doc.pdf">Download PDF</a></p>
When the helper is used as both the link text and the URL, the resolved URL appears in both places:
echo $converter->convert("[route('home')](route('home'))"); // <p><a href="https://domain.com">https://domain.com</a></p>
Angle brackets work too, which can help with complex arguments:
echo $converter->convert("[Home](<route('home', absolute: false)>)"); // <p><a href="/">Home</a></p>
You can freely mix helpers with regular Markdown links in the same document:
echo $converter->convert("[Home](route('home')) | [Docs](url('docs')) | [Google](https://google.com)"); // <p><a href="https://domain.com">Home</a> | <a href="https://domain.com/docs">Docs</a> | <a href="https://google.com">Google</a></p>
Images
Image syntax works the same way. Put a helper inside  and it resolves just like links do:
echo $converter->convert(")"); // <p><img src="https://domain.com/images/logo.png" alt="Logo" /></p> echo $converter->convert(")"); // <p><img src="https://domain.com/images/banner.jpg" alt="Banner" /></p> echo $converter->convert(")"); // <p><img src="https://domain.com/product/3" alt="Product" /></p>
The asset() helper is the most common choice for images. If you're on Vapor or any setup that serves assets from a CDN, asset() gives you the correct absolute URL instead of a broken relative path.
Regular images without helpers pass through untouched:
echo $converter->convert(""); // <p><img src="https://example.com/photo.jpg" alt="Photo" /></p>
For more details on CommonMark extensions and environments, check the CommonMark documentation.
Spatie Laravel Markdown
If you're using the Laravel Markdown package by Spatie, register the extension in config/markdown.php:
/* * These extensions should be added to the markdown environment. A valid * extension implements League\CommonMark\Extension\ExtensionInterface * * More info: https://commonmark.thephpleague.com/2.4/extensions/overview/ */ 'extensions' => [ Mozex\CommonMarkRoutes\RoutesExtension::class, ],
Resources
Visit the documentation site for searchable docs, auto-updated from this repository.
- AI Integration: Use this package with AI coding assistants via Context7 and Laravel Boost
- Requirements: PHP, Laravel, and dependency versions
- Changelog: Release history with linked pull requests and diffs
- Contributing: Development setup, code quality, and PR guidelines
- Questions & Issues: Bug reports, feature requests, and help
- Security: Report vulnerabilities directly via email
License
The MIT License (MIT). Please see License File for more information.
mozex/commonmark-routes 适用场景与选型建议
mozex/commonmark-routes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.17k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 06 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「documentation」 「php」 「asset」 「cms」 「url」 「markdown」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mozex/commonmark-routes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mozex/commonmark-routes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mozex/commonmark-routes 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Bookdown.io With Bootswatch Styles And Prism Syntax Highlighting
Laravel package that generates RESTful API documentation in Markdown based on PHPDoc.
Asset for Bulma Free for YiiFramework v.3.0.
Laravel API documentation generating tool
Symfony Utils Bundle
Asset Bundle to include Masonry on your Yii 2 project
统计信息
- 总下载量: 8.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-06-28