weiph/commonmark-section-extension

安装: 226

依赖: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

公开问题: 0

类型:commonmark-extension

0.1.0 2023-02-06 18:15 UTC

This package is auto-updated.

Last update: 2024-09-06 21:44:03 UTC


README

league/commonmark 扩展将标题及其相关内容包装成章节。

安装与基本用法

composer require weph/commonmark-section-extension

示例

use League\CommonMark\Environment\Environment;
use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
use League\CommonMark\MarkdownConverter;
use Weph\CommonMark\SectionExtension;

$environment = new Environment();
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addExtension(new SectionExtension());

$converter = new MarkdownConverter($environment);

echo $converter->convert(<<<EOMD
# Title

## Section 1

Section 1 content

### Section 1.1

Section 1.1 content

## Section 2

Section 2 content
EOMD
);

输出

<section>
    <h1>Title</h1>
    <section>
        <h2>Section 1</h2>
        <p>Section 1 content</p>
        <section>
            <h3>Section 1.1</h3>
            <p>Section 1.1 content</p>
        </section>
    </section>
    <section>
        <h2>Section 2</h2>
        <p>Section 2 content</p>
    </section>
</section>