承接 phpnomad/league-markdown-integration 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

phpnomad/league-markdown-integration

最新稳定版本:1.0.1

Composer 安装命令:

composer create-project phpnomad/league-markdown-integration

包简介

Implements PHPNomad Markdown implementations using League libraries

README 文档

README

Latest Version Total Downloads PHP Version License

Integrates League CommonMark and league/html-to-markdown with PHPNomad's phpnomad/markdown abstraction. It ships a single strategy class that satisfies both conversion contracts so your application can bind the interfaces in its container and stay unaware of the underlying library.

Installation

composer require phpnomad/league-markdown-integration

Composer pulls in phpnomad/markdown and both League libraries as transitive dependencies.

What This Provides

PHPNomad\LeagueMarkdownIntegration\Strategies\MarkdownConversionStrategy is the only class in the package. It does three things.

  • Implements both CanConvertMarkdownToHtml and CanConvertHtmlToMarkdown from phpnomad/markdown, so one binding covers both directions.
  • toHtml() delegates to League\CommonMark\CommonMarkConverter and rethrows CommonMarkException as ConvertToHtmlException.
  • toMarkdown() delegates to League\HTMLToMarkdown\HtmlConverter and rethrows InvalidArgumentException and RuntimeException as ConvertToMarkdownException.

Both League converters are constructed with their defaults. If you need custom CommonMark extensions or a non-default HTML-to-markdown configuration, write your own strategy class implementing the same interfaces and bind that instead.

Requirements

  • phpnomad/markdown for the conversion interfaces and exception hierarchy.
  • league/commonmark ^2.7 and league/html-to-markdown ^5.1 for the actual conversion work. Both come in through Composer automatically.

Usage

Register the strategy against both interfaces in a PHPNomad initializer so anything type-hinting CanConvertMarkdownToHtml or CanConvertHtmlToMarkdown resolves to the same implementation.

<?php

namespace MyApp\Content;

use PHPNomad\LeagueMarkdownIntegration\Strategies\MarkdownConversionStrategy;
use PHPNomad\Loader\Interfaces\HasClassDefinitions;
use PHPNomad\Markdown\Interfaces\CanConvertHtmlToMarkdown;
use PHPNomad\Markdown\Interfaces\CanConvertMarkdownToHtml;

final class Initializer implements HasClassDefinitions
{
    public function getClassDefinitions(): array
    {
        return [
            MarkdownConversionStrategy::class => [
                CanConvertMarkdownToHtml::class,
                CanConvertHtmlToMarkdown::class,
            ],
        ];
    }
}

Consumers type-hint the interfaces, not MarkdownConversionStrategy itself. Swapping implementations later is a one-line change in this initializer.

Documentation

Full PHPNomad documentation lives at phpnomad.com. For the underlying libraries, see the CommonMark and html-to-markdown project pages.

License

MIT. See LICENSE.

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固