rezozero/commonmark-ext-footnotes

This package is abandoned and no longer maintained. The author suggests using the league/commonmark package instead.

A footnote extension for CommonMark PHP implementation

Installs: 2 690

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 4

Forks: 3

Open Issues: 0

Type:commonmark-extension

1.0.3 2020-06-24 08:11 UTC

This package is auto-updated.

Last update: 2020-06-24 08:13:24 UTC


README

The Footnotes extension adds the ability to create footnotes in CommonMark documents.

Packagist Version Build Status

DEPRECATED

This extension has been deprecated. All of its functionality now exists in league/commonmark 1.5+ under the League\CommonMark\Extension\Footnote namespace, so you should upgrade to that version and use that bundled extension instead of this one.

Installation

This project can be installed via Composer:

composer require rezozero/commonmark-ext-footnotes

Usage

Configure your Environment as usual and simply add the FootnoteExtension provided by this package:

use League\CommonMark\Converter;
use League\CommonMark\DocParser;
use League\CommonMark\Environment;
use League\CommonMark\HtmlRenderer;
use RZ\CommonMark\Ext\Footnote\FootnoteExtension;

// Obtain a pre-configured Environment with all the standard CommonMark parsers/renderers ready-to-go
$environment = Environment::createCommonMarkEnvironment();

// Add this extension
$environment->addExtension(new FootnoteExtension());

// Instantiate the converter engine and start converting some Markdown!
$converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));

echo $converter->convertToHtml('# Hello World!');

Syntax

Code:

Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. 
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi[^note1] leo risus, porta ac consectetur ac.

[^note1]: Elit Malesuada Ridiculus

Result:

<p>
    Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    Morbi<sup id="fnref:note1"><a class="footnote-ref" href="#fn:note1" role="doc-noteref">1</a></sup> leo risus, porta ac consectetur ac.
</p>
<div class="footnotes">
    <hr />
    <ol>
        <li class="footnote" id="fn:note1">
            <p>
                Elit Malesuada Ridiculus <a class="footnote-backref" rev="footnote" href="#fnref:note1">&#8617;</a>
            </p>
        </li>
    </ol>
</div>