定制 mozex/commonmark-routes 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mozex/commonmark-routes

最新稳定版本:1.3.0

Composer 安装命令:

composer require mozex/commonmark-routes

包简介

Laravel routes in Markdown: A CommonMark extension to seamlessly use Laravel route functions within your Markdown content.

README 文档

README

Latest Version on Packagist GitHub Tests Workflow Status License Total Downloads

An extension for league/commonmark that allows you to use Laravel routes inside markdown, just as you would in your PHP code.

Warning: This extension is intended for use in controlled environments where the markdown is trusted. Do not use this extension for processing user-input markdown due to potential security risks.

Table of Contents

Support us

Creating and maintaining open-source projects requires significant time and effort. Your support will help enhance the project and enable further contributions to the PHP community.

Sponsorship can be made through the GitHub Sponsors program. Just click the "Sponsor" button at the top of this repository. Any amount is greatly appreciated, even a contribution as small as $1 can make a big difference and will go directly towards developing and improving this package.

Thank you for considering sponsoring. Your support truly makes a difference!

Installation

Requires PHP 8.1+

You can install the package via composer:

composer require mozex/commonmark-routes

Usage

Register RoutesExtension as a CommonMark extension and use the route function instead of URLs in your markdown, just as you would in your PHP code.

use League\CommonMark\Environment\Environment;
use League\CommonMark\CommonMarkConverter;
use Mozex\CommonMarkRoutes\RoutesExtension;

$converter = new CommonMarkConverter($environment);
$converter->getEnvironment()->addExtension(new RoutesExtension());

echo $converter->convert("[Home](route('home'))");
// Output: <p><a href="https://domain.com">Home</a></p>

echo $converter->convert("[Home](<route('home')>)");
// Output: <p><a href="https://domain.com">Home</a></p>

echo $converter->convert("[route('home')](route('home'))");
// Output: <p><a href="https://domain.com">https://domain.com</a></p>

echo $converter->convert("[<route('home')>](<route('home')>)");
// Output: <p><a href="https://domain.com">https://domain.com</a></p>

echo $converter->convert("[Home](route('home', absolute: false))");
// Output: <p><a href="/">Home</a></p>

echo $converter->convert("[Product](route('product', 3))");
// Output: <p><a href="https://domain.com/product/3">Product</a></p>

echo $converter->convert("[Features](route('home', ['id' => 'features']))");
// Output: <p><a href="https://domain.com?id=features">Features</a></p>

echo $converter->convert("[Features](route('home', ['id' => 'features'], false))");
// Output: <p><a href="/?id=features">Features</a></p>

echo $converter->convert("[route('home', ['id' => 'features'], false)](route('home', ['id' => 'features'], false))");
// Output: <p><a href="/?id=features">/?id=features</a></p>

For more information on CommonMark extensions and environments, refer to the CommonMark documentation.

Spatie Laravel Markdown

When using the Laravel Markdown package, you may 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,
],

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 3.89k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-28