Removed hard dependency on MarkdownParser code, now uses dflydev/markdown library

Refactored way how parsers are initialized, and allow to select parser while rendering
Interface `MarkdownParserInterface` method name was changed from `#transform($text)` to `#transformMarkdown($text)`
This commit is contained in:
Joseph Bielawski 2012-10-15 12:24:11 +02:00
parent 4169b545e7
commit 3c541b580b
22 changed files with 257 additions and 3220 deletions

View file

@ -0,0 +1,37 @@
<?php
namespace Knp\Bundle\MarkdownBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;
class ParsersCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('templating.helper.markdown')) {
return;
}
if (!$container->hasDefinition('markdown.parser')) {
return;
}
$defaultParserTag = $container->getDefinition('markdown.parser')->getTag('markdown.parser');
$definition = $container->getDefinition('templating.helper.markdown');
foreach ($container->findTaggedServiceIds('markdown.parser') as $id => $tags) {
if ($defaultParserTag == $id) {
$definition->addMethodCall('addParser', array(new Reference($id), 'default'));
continue;
}
foreach ($tags as $attributes) {
$alias = empty($attributes['alias']) ? $id : $attributes['alias'];
$definition->addMethodCall('addParser', array(new Reference($id), $alias));
}
}
}
}

View file

@ -2,20 +2,21 @@
namespace Knp\Bundle\MarkdownBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
class KnpMarkdownExtension extends Extension
{
/**
* Handles the knp_markdown configuration.
*
* @param array $configs The configurations being loaded
* @param array $configs The configurations being loaded
* @param ContainerBuilder $container
*
* @throws InvalidConfigurationException When Sundown parser was selected, but extension is not available
*/
public function load(array $configs , ContainerBuilder $container)
{
@ -28,12 +29,12 @@ class KnpMarkdownExtension extends Extension
$loader->load('helper.xml');
$loader->load('twig.xml');
if ($config['parser']['service'] == 'markdown.parser.sundown' && !class_exists('Sundown\Markdown')) {
throw new InvalidConfigurationException('Sundown parser selected, but required extension is not installed or configured.');
}
$container->setParameter('markdown.sundown.extensions', $config['sundown']['extensions']);
$container->setParameter('markdown.sundown.render_flags', $config['sundown']['render_flags']);
$container->setAlias('markdown.parser', $config['parser']['service']);
if ($config['parser']['service'] == 'markdown.parser.sundown' && !class_exists('Sundown\Markdown')) {
throw new InvalidConfigurationException('Sundown extension not installed or configured.');
}
}
}

View file

@ -8,14 +8,43 @@ use Knp\Bundle\MarkdownBundle\MarkdownParserInterface;
class MarkdownHelper implements HelperInterface
{
/**
* @var MarkdownParserInterface
* @var MarkdownParserInterface[]
*/
protected $parser;
protected $charset = 'UTF-8';
private $parsers = array();
private $charset = 'UTF-8';
public function __construct(MarkdownParserInterface $parser)
/**
* @param MarkdownParserInterface $parser
* @param string $alias
*/
public function addParser(MarkdownParserInterface $parser, $alias)
{
$this->parser = $parser;
$this->parsers[$alias] = $parser;
}
/**
* Transforms markdown syntax to HTML
*
* @param string $markdownText The markdown syntax text
* @param null|string $parserName
*
* @return string The HTML code
*
* @throws \RuntimeException
*/
public function transform($markdownText, $parserName = null)
{
if (null === $parserName) {
$parserName = 'default';
}
if (!isset($this->parsers[$parserName])) {
throw new \RuntimeException(sprintf('Unknown parser selected ("%s"), available are: %s', $parserName, implode(', ', array_keys($this->parsers))));
}
$parser = $this->parsers[$parserName];
return $parser->transformMarkdown($markdownText);
}
/**
@ -38,18 +67,11 @@ class MarkdownHelper implements HelperInterface
return $this->charset;
}
/**
* {@inheritDoc}
*/
public function getName()
{
return 'markdown';
}
/**
* Transforms markdown syntax to HTML
* @param string $markdownText The markdown syntax text
* @return string The HTML code
*/
public function transform($markdownText)
{
return $this->parser->transform($markdownText);
}
}

View file

@ -2,8 +2,14 @@
namespace Knp\Bundle\MarkdownBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle as BaseBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Knp\Bundle\MarkdownBundle\DependencyInjection\Compiler\ParsersCompilerPass;
class KnpMarkdownBundle extends BaseBundle
class KnpMarkdownBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new ParsersCompilerPass());
}
}

View file

@ -8,7 +8,8 @@ interface MarkdownParserInterface
* Converts text to html using markdown rules
*
* @param string $text plain text
*
* @return string rendered html
*/
function transform($text);
function transformMarkdown($text);
}

View file

@ -4,9 +4,7 @@ namespace Knp\Bundle\MarkdownBundle\Parser;
use Knp\Bundle\MarkdownBundle\MarkdownParserInterface;
if(!class_exists('\MarkdownExtraParser')) {
require_once(realpath(__DIR__.'/..').'/vendor/parser/MarkdownExtraParser.php');
}
use dflydev\markdown\MarkdownExtraParser;
/**
* MarkdownParser
@ -14,12 +12,12 @@ if(!class_exists('\MarkdownExtraParser')) {
* This class extends the original Markdown parser.
* It allows to disable unwanted features to increase performances.
*/
class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInterface
class MarkdownParser extends MarkdownExtraParser implements MarkdownParserInterface
{
/**
* @var array enabled features
* use the constructor to disable some of them
* Use the constructor to disable some of them
*
* @var array Enabled features
*/
protected $features = array(
'header' => true,
@ -90,20 +88,32 @@ class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInter
if (!$this->features['reference_link']) {
unset($this->document_gamut['stripLinkDefinitions']);
}
if(!$this->features['block_quote']) {
if (!$this->features['block_quote']) {
unset($this->block_gamut['doBlockQuotes']);
}
if(!$this->features['code_block']) {
if (!$this->features['code_block']) {
unset($this->block_gamut['doCodeBlocks']);
}
if(!$this->features['auto_link']) {
if (!$this->features['auto_link']) {
unset($this->span_gamut['doAutoLinks']);
}
if(!$this->features['entities'] && !$this->features['no_html']) {
if (!$this->features['entities'] && !$this->features['no_html']) {
$this->no_entities = true;
}
}
/**
* {@inheritDoc}
*/
public function transformMarkdown($text)
{
if ($this->features['no_html']) {
$text = htmlspecialchars($text, ENT_NOQUOTES);
}
return parent::transformMarkdown($text);
}
/**
* MarkdownExtraParser overwritten methods
*/
@ -111,11 +121,12 @@ class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInter
/**
* Simplify detab
*/
protected function detab($text)
public function detab($text)
{
return str_replace("\t", str_repeat(' ', $this->tab_width), $text);
}
protected function _initDetab()
public function _initDetab()
{
return;
}
@ -123,7 +134,7 @@ class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInter
/**
* Disable unless html_block
*/
protected function hashHTMLBlocks($text)
public function hashHTMLBlocks($text)
{
if (!$this->features['html_block']) {
return $text;
@ -135,12 +146,10 @@ class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInter
/**
* Disable mailto unless auto_mailto
*/
protected function doAutoLinks($text)
public function doAutoLinks($text)
{
if(!$this->features['auto_mailto'])
{
return preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i',
array(&$this, '_doAutoLinks_url_callback'), $text);
if (!$this->features['auto_mailto']) {
return preg_replace_callback('{<((https?|ftp|dict):[^\'">\s]+)>}i', array(&$this, '_doAutoLinks_url_callback'), $text);
}
return parent::doAutoLinks($text);
@ -149,13 +158,14 @@ class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInter
/**
* Conditional features: reference_link, inline_link,
*/
protected function doAnchors($text)
public function doAnchors($text)
{
#
# Turn Markdown link shortcuts into XHTML <a> tags.
#
if ($this->in_anchor)
if ($this->in_anchor) {
return $text;
}
$this->in_anchor = true;
#
@ -163,16 +173,16 @@ class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInter
#
if ($this->features['reference_link']) {
$text = preg_replace_callback('{
( # wrap whole match in $1
( # wrap whole match in $1
\[
('.$this->nested_brackets_re.') # link text = $2
\]
[ ]? # one optional space
(?:\n[ ]*)? # one optional newline followed by spaces
[ ]? # one optional space
(?:\n[ ]*)? # one optional newline followed by spaces
\[
(.*?) # id = $3
(.*?) # id = $3
\]
)
}xs',
@ -184,24 +194,24 @@ class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInter
#
if ($this->features['inline_link']) {
$text = preg_replace_callback('{
( # wrap whole match in $1
( # wrap whole match in $1
\[
('.$this->nested_brackets_re.') # link text = $2
\]
\( # literal paren
\( # literal parent
[ \n]*
(?:
<(.+?)> # href = $3
<(.+?)> # href = $3
|
('.$this->nested_url_parenthesis_re.') # href = $4
)
[ \n]*
( # $5
([\'"]) # quote char = $6
(.*?) # Title = $7
\6 # matching quote
[ \n]* # ignore any spaces/tabs between closing quote and )
)? # title is optional
( # $5
([\'"]) # quote char = $6
(.*?) # Title = $7
\6 # matching quote
[ \n]* # ignore any spaces/tabs between closing quote and )
)? # title is optional
\)
)
}xs',
@ -215,9 +225,9 @@ class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInter
#
if ($this->features['shortcut_link']) {
$text = preg_replace_callback('{
( # wrap whole match in $1
( # wrap whole match in $1
\[
([^\[\]]+) # link text = $2; can\'t contain [ or ]
([^\[\]]+) # link text = $2; can\'t contain [ or ]
\]
)
}xs',
@ -225,18 +235,11 @@ class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInter
}
$this->in_anchor = false;
return $text;
}
public function transform($text)
{
if ($this->features['no_html']) {
$text = htmlspecialchars($text, ENT_NOQUOTES);
}
return parent::transform($text);
}
protected function _doCodeBlocks_callback($matches)
public function _doCodeBlocks_callback($matches)
{
$codeblock = $matches[1];
@ -247,12 +250,12 @@ class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInter
# trim leading newlines and trailing newlines
$codeblock = preg_replace('/\A\n+|\n+\z/', '', $codeblock);
$codeblock = "<pre><code>$codeblock\n</code></pre>";
return "\n\n".$this->hashBlock($codeblock)."\n\n";
}
protected function makeCodeSpan($code)
public function makeCodeSpan($code)
{
if (!$this->features['no_html']) {
$code = htmlspecialchars(trim($code), ENT_NOQUOTES);
@ -263,7 +266,7 @@ class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInter
return $this->hashPart("<code>$code</code>");
}
protected function _doFencedCodeBlocks_callback($matches)
public function _doFencedCodeBlocks_callback($matches)
{
$codeblock = $matches[2];
if (!$this->features['no_html']) {
@ -272,6 +275,7 @@ class MarkdownParser extends \MarkdownExtraParser implements MarkdownParserInter
$codeblock = preg_replace_callback('/^\n+/',
array(&$this, '_doFencedCodeBlocks_newlines'), $codeblock);
$codeblock = "<pre><code>$codeblock</code></pre>";
return "\n\n".$this->hashBlock($codeblock)."\n\n";
}
}

View file

@ -9,7 +9,9 @@ use Knp\Bundle\MarkdownBundle\Parser\MarkdownParser;
*/
class Light extends MarkdownParser
{
/**
* @var array Enabled features
*/
protected $features = array(
'header' => true,
'list' => true,
@ -30,5 +32,4 @@ class Light extends MarkdownParser
'entities' => false,
'no_html' => false,
);
}

View file

@ -9,7 +9,9 @@ use Knp\Bundle\MarkdownBundle\Parser\MarkdownParser;
*/
class Medium extends MarkdownParser
{
/**
* @var array Enabled features
*/
protected $features = array(
'header' => true,
'list' => true,
@ -30,5 +32,4 @@ class Medium extends MarkdownParser
'entities' => false,
'no_html' => false,
);
}

View file

@ -9,7 +9,6 @@ use Knp\Bundle\MarkdownBundle\Parser\MarkdownParser;
*/
class Min extends MarkdownParser
{
public function __construct(array $features = array())
{
foreach ($this->features as $name => $enabled) {
@ -18,6 +17,5 @@ class Min extends MarkdownParser
return parent::__construct($features);
}
}

View file

@ -23,8 +23,8 @@ class SundownParser implements MarkdownParserInterface
/**
* {@inheritdoc}
*/
public function transform($text)
public function transformMarkdown($text)
{
return $this->parser->render($text);
}
}
}

View file

@ -1,52 +1,83 @@
Provide markdown conversion to your Symfony2 projects.
This implementation is based on Michel Fortin work.
We added PHP5 sugar, feature selection, and unit tests.
Provide markdown conversion (based on Michel Fortin work) to your Symfony2 projects.
[![Build Status](https://secure.travis-ci.org/KnpLabs/KnpMarkdownBundle.png)](http://travis-ci.org/KnpLabs/KnpMarkdownBundle)
## INSTALLATION
Add the following entry to ``deps`` the run ``php bin/vendors install``.
Symfony 2.0) Add the following entry to ``deps`` the run ``php bin/vendors install``.
[KnpMarkdownBundle]
git=http://github.com/KnpLabs/KnpMarkdownBundle.git
target=/bundles/Knp/Bundle/MarkdownBundle
```
[KnpMarkdownBundle]
git=https://github.com/KnpLabs/KnpMarkdownBundle
target=/bundles/Knp/Bundle/MarkdownBundle
Register the bundle in ``app/AppKernel.php``
[dflydev-markdown]
git=https://github.com/dflydev/dflydev-markdown
target=dflydev-markdown
```
$bundles = array(
// ...
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
);
And register namespace in ``app/autoload.php``
Register namespace in ``app/autoload.php``
```php
$loader->registerNamespaces(array(
// ...
'dflydev' => __DIR__.'/../vendor/dflydev-markdown/src'
'Knp' => __DIR__.'/../vendor/bundles',
));
```
$loader->registerNamespaces(array(
// ...
'Knp' => __DIR__.'/../vendor/bundles',
));
Symfony 2.1) Add HWIOAuthBundle to your `composer.json`
```yaml
{
"require": {
"knplabs/knp-markdown-bundle": "1.2.*@dev"
}
}
```
Symfony 2.0 & 2.1) Register the bundle in ``app/AppKernel.php``
```php
$bundles = array(
// ...
new Knp\Bundle\MarkdownBundle\KnpMarkdownBundle(),
);
```
## USAGE
// Use the service
$html = $this->container->get('markdown.parser')->transform($text);
```php
// Use the service
$html = $this->container->get('markdown.parser')->transformMarkdown($text);
// Use the helper
echo $view['markdown']->transform($text);
// Use the helper with default parser
echo $view['markdown']->transform($text);
// Use the helper and a select specific parser
echo $view['markdown']->transform($text, $parserName);
```
If you have enabled the Twig markdown filter, you can use the following in your Twig templates:
{{ my_data | markdown }}
```twig
{# Use default parser #}
{{ my_data|markdown }}
{# Or select specific parser #}
{{ my_data|markdown('parserName') }}
```
## Change the parser implementation
Create a service implementing Knp\Bundle\MarkdownBundle\MarkdownParserInterface,
Create a service implementing `Knp\Bundle\MarkdownBundle\MarkdownParserInterface`,
then configure the bundle to use it:
knp_markdown:
parser:
service: my.markdown.parser
```yaml
knp_markdown:
parser:
service: my.markdown.parser
```
Alternatively if you are using the ``markdown.parser.sundown`` there are
options for enabling sundown extensions and render flags, see the
@ -58,11 +89,11 @@ This bundle comes with 5 parser services, 4 based on the same algorithm
but providing different levels of compliance to the markdown specification,
and one which is uses the php sundown extension:
- markdown.parser.max // fully compliant = slower (default implementation)
- markdown.parser.medium // expensive and uncommon features dropped
- markdown.parser.light // expensive features dropped
- markdown.parser.min // most features dropped = faster
- markdown.parser.sundown // faster and fully compliant (recommended)
- markdown.parser.max // fully compliant = slower (default implementation)
- markdown.parser.medium // expensive and uncommon features dropped
- markdown.parser.light // expensive features dropped
- markdown.parser.min // most features dropped = faster
- markdown.parser.sundown // faster and fully compliant (recommended)
``markdown.parser.sundown`` requires [php sundown extension](https://github.com/chobie/php-sundown).

View file

@ -1,21 +1,16 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
<parameters>
<parameter key="templating.helper.markdown.class">Knp\Bundle\MarkdownBundle\Helper\MarkdownHelper</parameter>
</parameters>
<parameter key="templating.helper.markdown.class">Knp\Bundle\MarkdownBundle\Helper\MarkdownHelper</parameter>
</parameters>
<services>
<service id="templating.helper.markdown" class="%templating.helper.markdown.class%" public="false">
<tag name="templating.helper" alias="markdown" />
<argument type="service" id="markdown.parser" />
</service>
</services>
<services>
<service id="templating.helper.markdown" class="%templating.helper.markdown.class%" public="false">
<argument type="service" id="markdown.parser" />
<tag name="templating.helper" alias="markdown" />
</service>
</services>
</container>

View file

@ -1,21 +1,29 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="markdown.parser.min" class="Knp\Bundle\MarkdownBundle\Parser\Preset\Min" />
<service id="markdown.parser.light" class="Knp\Bundle\MarkdownBundle\Parser\Preset\Light" />
<service id="markdown.parser.medium" class="Knp\Bundle\MarkdownBundle\Parser\Preset\Medium" />
<service id="markdown.parser.max" class="Knp\Bundle\MarkdownBundle\Parser\Preset\Max" />
<service id="markdown.parser.min" class="Knp\Bundle\MarkdownBundle\Parser\Preset\Min" public="false">
<tag name="markdown.parser" alias="min" />
</service>
<service id="markdown.parser.light" class="Knp\Bundle\MarkdownBundle\Parser\Preset\Light" public="false">
<tag name="markdown.parser" alias="light" />
</service>
<service id="markdown.parser.medium" class="Knp\Bundle\MarkdownBundle\Parser\Preset\Medium" public="false">
<tag name="markdown.parser" alias="medium" />
</service>
<service id="markdown.parser.max" class="Knp\Bundle\MarkdownBundle\Parser\Preset\Max" public="false">
<tag name="markdown.parser" alias="max" />
</service>
<service id="markdown.parser.sundown" public="false" class="Knp\Bundle\MarkdownBundle\Parser\SundownParser">
<argument type="service" id="markdown.sundown.base_parser"/>
<service id="markdown.parser.sundown" class="Knp\Bundle\MarkdownBundle\Parser\SundownParser" public="false">
<argument type="service" id="markdown.sundown.base_parser" />
<tag name="markdown.parser" alias="sundown" />
</service>
<service id="markdown.sundown.base_parser" public="false" class="Sundown\Markdown">
<argument type="service" id="markdown.sundown.renderer"/>
<argument type="service" id="markdown.sundown.renderer" />
<argument>%markdown.sundown.extensions%</argument>
</service>
@ -23,5 +31,4 @@
<argument>%markdown.sundown.render_flags%</argument>
</service>
</services>
</container>

View file

@ -1,5 +1,4 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
@ -10,5 +9,4 @@
<tag name="twig.extension" />
</service>
</services>
</container>

View file

@ -6,7 +6,6 @@ use Knp\Bundle\MarkdownBundle\Parser\MarkdownParser as Parser;
class FeatureTest extends \PHPUnit_Framework_TestCase
{
public function testParser()
{
$parser = new Parser();
@ -131,7 +130,7 @@ EOF;
sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere
lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae,
risus.</p>
<p>Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.</p>
</blockquote>
@ -156,11 +155,11 @@ EOF;
$html = <<<EOF
<blockquote>
<p>Ceci est le premier niveau de citation.</p>
<blockquote>
<p>Ceci est un bloc de citation imbriqué.</p>
</blockquote>
<p>Retour au premier niveau.</p>
</blockquote>
@ -188,12 +187,12 @@ EOF;
$html = <<<EOF
<blockquote>
<h2>This is a header.</h2>
<ol>
<li>This is the first list item.</li>
<li>This is the second list item.</li>
</ol>
<p>Here's some example code:</p>
<pre><code>return shell_exec("echo \$input | \$markdown_script");

View file

@ -2,13 +2,10 @@
namespace Knp\Bundle\MarkdownBundle\Tests;
use Knp\Bundle\MarkdownBundle\Parser\MarkdownParser as Parser;
use Knp\Bundle\MarkdownBundle\Parser\Preset as Preset;
class PresetTest extends \PHPUnit_Framework_TestCase
{
public function testMax()
{
$parser = new Preset\Max();

View file

@ -20,9 +20,9 @@ class MarkdownTwigExtension extends \Twig_Extension
);
}
public function markdown($txt)
public function markdown($text, $parser = null)
{
return $this->helper->transform($txt);
return $this->helper->transform($text, $parser);
}
public function getName()

View file

@ -19,7 +19,8 @@
"require": {
"php": ">=5.3.3",
"symfony/framework-bundle": ">=2.0,<2.3-dev"
"symfony/framework-bundle": ">=2.0,<2.3-dev",
"dflydev/markdown": "1.0.*@dev"
},
"suggest": {
@ -27,6 +28,12 @@
"ext-sundown": "to use optional support for php-sundown extension instead of php implementation"
},
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
}
},
"autoload": {
"psr-0": {
"Knp\\Bundle\\MarkdownBundle": ""

40
vendor/parser/LICENSE vendored
View file

@ -1,40 +0,0 @@
PHP Markdown
Copyright (c) 2010 knplabs
<http://knplabs.com/>
Based on Markdown
Copyright (c) 2004-2009 Michel Fortin
<http://michelf.com/>
All rights reserved.
Based on Markdown
Copyright (c) 2003-2006 John Gruber
<http://daringfireball.net/>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name "Markdown" nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.
This software is provided by the copyright holders and contributors "as
is" and any express or implied warranties, including, but not limited
to, the implied warranties of merchantability and fitness for a
particular purpose are disclaimed. In no event shall the copyright owner
or contributors be liable for any direct, indirect, incidental, special,
exemplary, or consequential damages (including, but not limited to,
procurement of substitute goods or services; loss of use, data, or
profits; or business interruption) however caused and on any theory of
liability, whether in contract, strict liability, or tort (including
negligence or otherwise) arising in any way out of the use of this
software, even if advised of the possibility of such damage.

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,179 +0,0 @@
PHP Markdown
============
Version 1.0.1m - Sat 21 Jun 2008
by Michel Fortin
<http://michelf.com/>
based on work by John Gruber
<http://daringfireball.net/>
Introduction
------------
Markdown is a text-to-HTML conversion tool for web writers. Markdown
allows you to write using an easy-to-read, easy-to-write plain text
format, then convert it to structurally valid XHTML (or HTML).
"Markdown" is two things: a plain text markup syntax, and a software
tool, written in Perl, that converts the plain text markup to HTML.
PHP Markdown is a port to PHP of the original Markdown program by
John Gruber.
PHP Markdown can work as a plug-in for WordPress and bBlog, as a
modifier for the Smarty templating engine, or as a remplacement for
textile formatting in any software that support textile.
Full documentation of Markdown's syntax is available on John's
Markdown page: <http://daringfireball.net/projects/markdown/>
Installation and Requirement
----------------------------
PHP Markdown requires PHP version 4.0.5 or later.
### WordPress ###
PHP Markdown works with [WordPress][wp], version 1.2 or later.
[wp]: http://wordpress.org/
1. To use PHP Markdown with WordPress, place the "makrdown.php" file
in the "plugins" folder. This folder is located inside
"wp-content" at the root of your site:
(site home)/wp-content/plugins/
2. Activate the plugin with the administrative interface of
WordPress. In the "Plugins" section you will now find Markdown.
To activate the plugin, click on the "Activate" button on the
same line than Markdown. Your entries will now be formatted by
PHP Markdown.
3. To post Markdown content, you'll first have to disable the
"visual" editor in the User section of WordPress.
You can configure PHP Markdown to not apply to the comments on your
WordPress weblog. See the "Configuration" section below.
It is not possible at this time to apply a different set of
filters to different entries. All your entries will be formated by
PHP Markdown. This is a limitation of WordPress. If your old entries
are written in HTML (as opposed to another formatting syntax, like
Textile), they'll probably stay fine after installing Markdown.
### bBlog ###
PHP Markdown also works with [bBlog][bb].
[bb]: http://www.bblog.com/
To use PHP Markdown with bBlog, rename "markdown.php" to
"modifier.markdown.php" and place the file in the "bBlog_plugins"
folder. This folder is located inside the "bblog" directory of
your site, like this:
(site home)/bblog/bBlog_plugins/modifier.markdown.php
Select "Markdown" as the "Entry Modifier" when you post a new
entry. This setting will only apply to the entry you are editing.
### Replacing Textile in TextPattern ###
[TextPattern][tp] use [Textile][tx] to format your text. You can
replace Textile by Markdown in TextPattern without having to change
any code by using the *Texitle Compatibility Mode*. This may work
with other software that expect Textile too.
[tx]: http://www.textism.com/tools/textile/
[tp]: http://www.textpattern.com/
1. Rename the "markdown.php" file to "classTextile.php". This will
make PHP Markdown behave as if it was the actual Textile parser.
2. Replace the "classTextile.php" file TextPattern installed in your
web directory. It can be found in the "lib" directory:
(site home)/textpattern/lib/
Contrary to Textile, Markdown does not convert quotes to curly ones
and does not convert multiple hyphens (`--` and `---`) into en- and
em-dashes. If you use PHP Markdown in Textile Compatibility Mode, you
can solve this problem by installing the "smartypants.php" file from
[PHP SmartyPants][psp] beside the "classTextile.php" file. The Textile
Compatibility Mode function will use SmartyPants automatically without
further modification.
[psp]: http://michelf.com/projects/php-smartypants/
### Updating Markdown in Other Programs ###
Many web applications now ship with PHP Markdown, or have plugins to
perform the conversion to HTML. You can update PHP Markdown in many of
these programs by swapping the old "markdown.php" file for the new one.
Here is a short non-exhaustive list of some programs and where they
hide the "markdown.php" file.
| Program | Path to Markdown
| ------- | ----------------
| [Pivot][] | `(site home)/pivot/includes/markdown/markdown.php`
If you're unsure if you can do this with your application, ask the
developer, or wait for the developer to update his application or
plugin with the new version of PHP Markdown.
[Pivot]: http://pivotlog.net/
### In Your Own Programs ###
You can use PHP Markdown easily in your current PHP program. Simply
include the file and then call the Markdown function on the text you
want to convert:
include_once "markdown.php";
$my_html = Markdown($my_text);
If you wish to use PHP Markdown with another text filter function
built to parse HTML, you should filter the text *after* the Markdown
function call. This is an example with [PHP SmartyPants][psp]:
$my_html = SmartyPants(Markdown($my_text));
### With Smarty ###
If your program use the [Smarty][sm] template engine, PHP Markdown
can now be used as a modifier for your templates. Rename "markdown.php"
to "modifier.markdown.php" and put it in your smarty plugins folder.
[sm]: http://smarty.php.net/
If you are using MovableType 3.1 or later, the Smarty plugin folder is
located at `(MT CGI root)/php/extlib/smarty/plugins`. This will allow
Markdown to work on dynamic pages.
Configuration
-------------
By default, PHP Markdown produces XHTML output for tags with empty
elements. E.g.:
<br />
Markdown can be configured to produce HTML-style tags; e.g.:
<br>
To do this, you must edit the "MARKDOWN_EMPTY_ELEMENT_SUFFIX"
definition below the "Global default settings" header at the start of
the "markdown.php" file.