Skip to content

A Commonmark extension that wraps headings and associated content into sections

License

Notifications You must be signed in to change notification settings

weph/commonmark-section-extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

weph/commonmark-section-extension

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>

About

A Commonmark extension that wraps headings and associated content into sections

Resources

License

Stars

Watchers

Forks

Packages

No packages published