2017 © Pedro Peláez
 

library magl-markdown

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

image

maglnet/magl-markdown

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

  • Wednesday, March 21, 2018
  • by maglnet
  • Repository
  • 4 Watchers
  • 23 Stars
  • 54,426 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 3 Forks
  • 1 Open issues
  • 16 Versions
  • 4 % Grown

The README.md

MaglMarkdown - ZF2 View Helper For Markdown

Build Status Latest Stable Version License Scrutinizer Code Quality Code Coverage Dependency Status, (*1)

Introduction

MaglMarkdown is a ZF2 module that adds a View Helper to transform Markdown. To change between different renderers have a look at the config section, (*2)

You can use one of the following parsers for your Markdown:
* The PHP-Markdown parser from Michel Fortin * The PHP-MarkdownExtra parser from Michel Fortin (this is the default) * The Parsedown parser from Emanuil Rusev * The Parsedown-Extra parser from Emanuil Rusev * Github Markdown Api * you should provide an access_token within the config, to avoid hitting the rate_limit too soon * it's highly recommended to enable caching if you use the Github Api because of the mentioned rate_limit and to boost performance * The PHP League's CommonMark implementation, (*3)

Installation

You can install the module with composer by adding the following "require" to your composer.json, (*4)

{
    "require": {
        "maglnet/magl-markdown": "~1.1"
    }
}

after that you need to run, (*5)

$ php composer.phar update

and enable the module within your application.config.php, (*6)

array(
    'modules' => array(
        'Application',
        'MaglMarkdown',
    ),
);

Usage

View Helper

Simply use it within your Views like this, (*7)

$this->markdown('Yes, **this** is *Markdown*!');

Service Manager

You can get the MarkdownService through the Service Manager, to use the render() method wherever you like within you zf2 application. MarkdownService automatically uses caching if it has been enabled within the config., (*8)

/* @var $markdownService MaglMarkdown\Service\Markdown */
$markdownService = $serviceManager->get('MaglMarkdown\MarkdownService');
$html = $markdownService->render('Yes, **this** is *Markdown*!');

You can also get a MarkdownAdapter through the Service Manager and use transformText() to get your Markdown rendered to HTML.
This is NOT recommended anymore. Use the above mentioned MarkdownService instead because it can use the provided caching mechanism., (*9)

/* @var $markdownAdapter MaglMarkdown\Adapter\MarkdownAdapterInterface */
$markdownAdapter = $serviceManager->get('MaglMarkdown\MarkdownAdapter');
$html = $markdownAdapter->transformText('Yes, **this** is *Markdown*!');

Security warning:
You should be aware, that your markdown could contain insecure content (e.g. user generated content). So use something like HTMLPurifier to sanitize your output., (*10)

Configuration

Copy the provided config file config/maglmarkdown.local.php to your autoloading directory YourZF2Application/config/autoload/maglmarkdown.local.php and adjust it to your needs.
By default PHP-MarkdownExtra parser by Michel Fortin is used., (*11)

Cache

By default, caching is disabled. Set cache_enabled to true within config/maglmarkdown.local.php to enable the caching. Caching could be very helpful if you have large markdown files/texts or if you're using an Adapter that relies on third-party APIs that either are rate limited or take a long time to render., (*12)

A simple filesystem cache is configured by default, but feel free to configure your own adapter., (*13)

Adding own parsers

It is possible to add your own parser implementation.
All you have to do, is to write a class that implements the MaglMarkdown\Adapter\MarkdownAdapterInterface interface and make it available through the service manager.
After that override the alias MaglMarkdown\MarkdownAdapterto point to your custom adapter.
MaglMarkdown will then use this class to transform the Markdown., (*14)

array(
    'aliases' => array(
        'MaglMarkdown\MarkdownAdapter' => 'Your\Own\MarkdownAdapter', //needs to implement MaglMarkdown\Adapter\MarkdownAdapterInterface
    ),
)

Events

The markdown service triggers two events you can listen to: * markdown.render.pre before rendering (with the markdown text as parameter) * markdown.render.post after rendering (with the rendered markdown as parameter), (*15)

These events are currently used for the integrated caching feature only, but do whatever you like with these events., (*16)

Contributors

MaglMarkdown is developed by Matthias Glaub and contributors., (*17)

License

MaglMarkdown is licensed under the MIT license.
See the included LICENSE file., (*18)

Based on PHP Markdown Lib
Copyright (c) 2004-2013 Michel Fortin
http://michelf.ca/
All rights reserved., (*19)

Based on parsedown
Copyright (c) 2013 Emanuil Rusev
http://erusev.com/
All rights reserved., (*20)

Based on The PHP League's Common Mark implementation
Copyright (c) 2014, Colin O'Dell
https://github.com/thephpleague/commonmark
All rights reserved., (*21)

Based on Markdown
Copyright (c) 2003-2005 John Gruber
http://daringfireball.net/
All rights reserved., (*22)

The Versions

09/01 2015

1.3.0

1.3.0.0 https://github.com/maglnet/MaglMarkdown

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

  Sources   Download

MIT

The Requires

 

The Development Requires

zf2 zend framework markdown parsedown gfm github flavoured markdown

23/11 2014

1.2.0

1.2.0.0 https://github.com/maglnet/MaglMarkdown

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

  Sources   Download

MIT

The Requires

 

The Development Requires

zf2 zend framework markdown parsedown gfm github flavoured markdown

25/05 2014

1.1.1

1.1.1.0 https://github.com/maglnet/MaglMarkdown

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

  Sources   Download

MIT

The Requires

 

The Development Requires

zf2 zend framework markdown parsedown gfm github flavoured markdown

11/05 2014

1.1.0

1.1.0.0 https://github.com/maglnet/MaglMarkdown

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

  Sources   Download

MIT

The Requires

 

The Development Requires

zf2 zend framework markdown parsedown

26/03 2014

1.0.6

1.0.6.0 https://github.com/maglnet/MaglMarkdown

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

  Sources   Download

MIT

The Requires

 

The Development Requires

zf2 zend framework markdown parsedown

26/02 2014

1.0.5

1.0.5.0 https://github.com/maglnet/MaglMarkdown

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

  Sources   Download

MIT

The Requires

 

The Development Requires

zf2 zend framework markdown parsedown

23/02 2014

1.0.4

1.0.4.0 https://github.com/maglnet/MaglMarkdown

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

  Sources   Download

LGPL-3.0

The Requires

 

The Development Requires

zf2 zend framework markdown parsedown

22/02 2014

1.0.3

1.0.3.0 https://github.com/maglnet/MaglMarkdown

Provides a ZF2 View Helper to render markdown syntax. It uses third-party libraries for the rendering and you can switch between different renderers.

  Sources   Download

LGPL-3.0

The Requires

 

zf2 zend framework markdown parsedown

22/02 2014

1.0.1

1.0.1.0 https://github.com/maglnet/MaglMarkdown

Provides a ZF2 View Helper to render markdown syntax

  Sources   Download

LGPL3

The Requires

 

22/02 2014

1.0.2

1.0.2.0 https://github.com/maglnet/MaglMarkdown

Provides a ZF2 View Helper to render markdown syntax

  Sources   Download

LGPL3

The Requires

 

22/02 2014

1.0.0

1.0.0.0 https://github.com/maglnet/MaglMarkdown

Provides a ZF2 View Helper to render markdown syntax

  Sources   Download

The Requires