2017 © Pedro Peláez
 

library twig-markdown

Twig extension to work with Markdown content

image

aptoma/twig-markdown

Twig extension to work with Markdown content

  • Friday, June 23, 2017
  • by gunnarlium
  • Repository
  • 10 Watchers
  • 135 Stars
  • 579,293 Installations
  • PHP
  • 31 Dependents
  • 1 Suggesters
  • 22 Forks
  • 3 Open issues
  • 10 Versions
  • 32 % Grown

The README.md

Twig Markdown Extension

Build Status, (*1)

THIS EXTENSION IS NO LONGER MAINTAINED, AND WE WILL NOT MAKE ANY NEW RELEASES. IF ANYONE WANTS TO TAKE OVER, PLEASE MAKE A FORK AND PUBLISH A NEW PACKAGE, AND WE'LL LINK TO THE NEW VERSION., (*2)

Twig Markdown extension provides a new filter and a tag to allow parsing of content as Markdown in Twig templates., (*3)

This extension could be integrated with several Markdown parser as it provides an interface, which allows you to customize your Markdown parser., (*4)

Supported parsers

Features

  • Filter support {{ "# Heading Level 1"|markdown }}
  • Tag support {% markdown %}{% endmarkdown %}

When used as a tag, the indentation level of the first line sets the default indentation level for the rest of the tag content. From this indentation level, all same indentation or outdented levels text will be transformed as regular text., (*5)

This feature allows you to write your Markdown content at any indentation level without caring of Markdown internal transformation:, (*6)



{{ title }}

{% markdown %} This is a list that is indented to match the context around the markdown tag: * List item 1 * List item 2 * Sub List Item * Sub Sub List Item The following block will be transformed as code, as it is indented more than the surrounding content: $code = "good"; {% endmarkdown %}

Installation

Run the composer command to install the latest stable version:, (*7)

composer require aptoma/twig-markdown

Or update your composer.json:, (*8)

{
    "require": {
        "aptoma/twig-markdown": "~3.0"
    }
}

You can choose to provide your own Markdown engine, although we recommend using michelf/php-markdown:, (*9)

composer require michelf/php-markdown ~1.8
{
    "require": {
        "michelf/php-markdown": "~1.8"
    }
}

You may also use the PHP League CommonMark engine:, (*10)

composer require league/commonmark ~0.19
{
    "require": {
        "league/commonmark": "~0.19"
    }
}

Usage

Twig Extension

The Twig extension provides the markdown tag and filter support., (*11)

Assuming that you are using composer autoloading, add the extension to the Twig environment:, (*12)


use Aptoma\Twig\Extension\MarkdownExtension; use Aptoma\Twig\Extension\MarkdownEngine; $engine = new MarkdownEngine\MichelfMarkdownEngine(); $twig->addExtension(new MarkdownExtension($engine));

Twig Token Parser

The Twig token parser provides the markdown tag only!, (*13)

use Aptoma\Twig\TokenParser\MarkdownTokenParser;

$twig->addTokenParser(new MarkdownTokenParser());

Symfony

To use this extension in a Symfony 3/4 app (including Pimcore), add the following snippet to your app's app/config/services.yml file:, (*14)

services:
    # ...

    markdown.engine:
        class: Aptoma\Twig\Extension\MarkdownEngine\MichelfMarkdownEngine
    twig.markdown:
        class: Aptoma\Twig\Extension\MarkdownExtension
        arguments: ['@markdown.engine']
        tags:
            - { name: twig.extension }

GitHub Markdown Engine

MarkdownEngine\GitHubMarkdownEngine provides an interface to GitHub's markdown engine using their public API via [KnpLabs\php-github-api][2]. To reduce API calls, rendered documents are hashed and cached in the filesystem. You can pass a GitHub repository and the path to be used for caching to the constructor:, (*15)

use Aptoma\Twig\Extension\MarkdownEngine;

$engine = new MarkdownEngine\GitHubMarkdownEngine(
    'aptoma/twig-markdown', // The GitHub repository to use as a context
    true,                   // Whether to use GitHub's Flavored Markdown (GFM)
    '/tmp/markdown-cache',  // Path on filesystem to store rendered documents
);

In order to authenticate the API client (for instance), it's possible to pass an own instance of \GitHub\Client instead of letting the engine create one itself:, (*16)

$client = new \Github\Client;
$client->authenticate('GITHUB_CLIENT_ID', 'GITHUB_CLIENT_SECRET', \Github\Client::AUTH_URL_CLIENT_ID);

$engine = new MarkdownEngine\GitHubMarkdownEngine('aptoma/twig-markdown', true, '/tmp/markdown-cache', $client);

Using a different Markdown parser engine

If you want to use a different Markdown parser, you need to create an adapter that implements Aptoma\Twig\Extension\MarkdownEngineInterface.php. Have a look at Aptoma\Twig\Extension\MarkdownEngine\MichelfMarkdownEngine for an example., (*17)

Tests

The test suite uses PHPUnit:, (*18)

$ phpunit

License

Twig Markdown Extension is licensed under the MIT license., (*19)

The Versions

23/06 2017

dev-master

9999999-dev

Twig extension to work with Markdown content

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joris Berthelot

twig markdown

23/06 2017

dev-travis

dev-travis

Twig extension to work with Markdown content

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joris Berthelot

twig markdown

23/06 2017

3.0.0

3.0.0.0

Twig extension to work with Markdown content

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joris Berthelot

twig markdown

25/03 2015

1.2.0

1.2.0.0

Twig extension to work with Markdown content

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joris Berthelot

twig markdown

06/01 2015

1.1.0

1.1.0.0

Twig extension to work with Markdown content

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joris Berthelot

twig markdown

24/07 2014

1.0.0

1.0.0.0

Twig extension to work with Markdown content

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joris Berthelot

twig markdown

26/09 2013

0.2.1

0.2.1.0

Twig extension to work with Markdown content

  Sources   Download

MIT

The Requires

 

The Development Requires

by Joris Berthelot

twig markdown

26/09 2013

0.2.0

0.2.0.0

Twig extension to work with Markdown content

  Sources   Download

MIT

The Requires

 

twig markdown

18/11 2012

0.1.0

0.1.0.0

Twig extension to work with Markdown content

  Sources   Download

MIT

The Requires

 

twig markdown