weph/commonmark-section-extension

Installs: 250

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:commonmark-extension

0.1.0 2023-02-06 18:15 UTC

This package is auto-updated.

Last update: 2024-11-06 22:01:38 UTC


README

This league/commonmark extension wraps headings and associated content into sections.

Installation & Basic Usage

composer require weph/commonmark-section-extension

Example:

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
);

Output:

<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>