Created
June 28, 2012 08:05
-
-
Save stof/3009812 to your computer and use it in GitHub Desktop.
Using Sundown in KnpMarkdownBundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
knp_markdown: | |
parser: | |
service: ls_common.sundown.markdown_parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> | |
<parameter key="ls_common.sundown.extensions" type="collection"> | |
<parameter key="no_intra_emphasis">true</parameter> | |
<parameter key="tables">true</parameter> | |
<parameter key="fenced_code_blocks">true</parameter> | |
<parameter key="autolink">true</parameter> | |
<parameter key="strikethrough">true</parameter> | |
<parameter key="lax_html_blocks">true</parameter> | |
</parameter> | |
<parameter key="ls_common.sundown.render_flags" type="collection"> | |
<parameter key="hard_wrap">true</parameter> | |
<parameter key="filter_html">true</parameter> | |
</parameter> | |
</parameters> | |
<services> | |
<service id="ls_common.sundown.markdown_parser" class="LS\CommonBundle\Markdown\SundownParser" public="false"> | |
<argument type="service" id="ls_common.sundown.parser" /> | |
</service> | |
<service id="ls_common.sundown.parser" class="Sundown\Markdown" public="false"> | |
<argument type="service" id="ls_common.sundown.renderer" /> | |
<argument>%ls_common.sundown.extensions%</argument> | |
</service> | |
<service id="ls_common.sundown.renderer" class="Sundown\Render\HTML" public="false"> | |
<argument>%ls_common.sundown.render_flags%</argument> | |
</service> | |
</services> | |
</container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace LS\CommonBundle\Markdown; | |
use Knp\Bundle\MarkdownBundle\MarkdownParserInterface; | |
use Sundown\Markdown; | |
/** | |
* SundownParser | |
* | |
* This class wraps the original Sundown parser to implement the KnpMardownBundle interface | |
*/ | |
class SundownParser implements MarkdownParserInterface | |
{ | |
private $parser; | |
public function __construct(Markdown $parser) | |
{ | |
$this->parser = $parser; | |
} | |
/** | |
* Converts text to html using markdown rules | |
* | |
* @param string $text plain text | |
* | |
* @return string rendered html | |
*/ | |
public function transform($text) | |
{ | |
return $this->parser->render($text); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment