mirror of
https://github.com/KnpLabs/KnpMarkdownBundle.git
synced 2024-05-20 14:26:33 +02:00
57 lines
1.1 KiB
PHP
57 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Knplabs\MarkdownBundle\Helper;
|
|
|
|
use Symfony\Component\Templating\Helper\HelperInterface;
|
|
use Knplabs\MarkdownBundle\Parser\MarkdownParser;
|
|
|
|
class MarkdownHelper implements HelperInterface
|
|
{
|
|
/**
|
|
* @var MarkdownParser
|
|
*/
|
|
protected $parser;
|
|
protected $charset = 'UTF-8';
|
|
|
|
public function __construct(MarkdownParser $parser)
|
|
{
|
|
$this->parser = $parser;
|
|
}
|
|
|
|
/**
|
|
* Sets the default charset.
|
|
*
|
|
* @param string $charset The charset
|
|
*/
|
|
public function setCharset($charset)
|
|
{
|
|
$this->charset = $charset;
|
|
}
|
|
|
|
/**
|
|
* Gets the default charset.
|
|
*
|
|
* @return string The default charset
|
|
*/
|
|
public function getCharset()
|
|
{
|
|
return $this->charset;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
}
|