added controller to render markdown documentation #129
This commit is contained in:
@@ -11,6 +11,7 @@ namespace App\Twig;
|
||||
|
||||
use Symfony\Component\Intl\Intl;
|
||||
use App\Entity\Timesheet;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
/**
|
||||
* Multiple Twig extensions: filters and functions
|
||||
@@ -37,11 +38,11 @@ class Extensions extends \Twig_Extension
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new \Twig_SimpleFilter('duration', array($this, 'duration')),
|
||||
new \Twig_SimpleFilter('durationForEntry', array($this, 'durationForEntry')),
|
||||
new \Twig_SimpleFilter('money', array($this, 'money')),
|
||||
new \Twig_SimpleFilter('currency', array($this, 'currency')),
|
||||
new \Twig_SimpleFilter('country', array($this, 'country')),
|
||||
new TwigFilter('duration', [$this, 'duration']),
|
||||
new TwigFilter('durationForEntry', [$this, 'durationForEntry']),
|
||||
new TwigFilter('money', [$this, 'money']),
|
||||
new TwigFilter('currency', [$this, 'currency']),
|
||||
new TwigFilter('country', [$this, 'country']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -140,12 +141,4 @@ class Extensions extends \Twig_Extension
|
||||
|
||||
return $locales;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'kimai.extension';
|
||||
}
|
||||
}
|
||||
|
||||
54
src/Twig/MarkdownExtension.php
Normal file
54
src/Twig/MarkdownExtension.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Twig;
|
||||
|
||||
use App\Utils\Markdown;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
/**
|
||||
* A twig extension to handle markdown parser.
|
||||
*/
|
||||
class MarkdownExtension extends \Twig_Extension
|
||||
{
|
||||
/**
|
||||
* @var Markdown
|
||||
*/
|
||||
private $markdown;
|
||||
|
||||
/**
|
||||
* MarkdownExtension constructor.
|
||||
* @param Markdown $parser
|
||||
*/
|
||||
public function __construct(Markdown $parser)
|
||||
{
|
||||
$this->markdown = $parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TwigFilter[]
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter('md2html', [$this, 'markdownToHtml'], ['is_safe' => ['html']]),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the given Markdown content into HTML
|
||||
*
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
public function markdownToHtml(string $content): string
|
||||
{
|
||||
return $this->markdown->toHtml($content);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user