allow markdown in timesheet descriptions (#296)

This commit is contained in:
Kevin Papst
2018-09-02 12:10:49 +02:00
committed by GitHub
parent 9f6079ad8a
commit 4c277fe1b5
13 changed files with 77 additions and 8 deletions

View File

@@ -21,14 +21,19 @@ class MarkdownExtension extends \Twig_Extension
* @var Markdown
*/
private $markdown;
/**
* @var bool
*/
private $timesheetIsMarkdown = false;
/**
* MarkdownExtension constructor.
* @param Markdown $parser
*/
public function __construct(Markdown $parser)
public function __construct(Markdown $parser, bool $timesheetAsMarkdown = false)
{
$this->markdown = $parser;
$this->timesheetIsMarkdown = $timesheetAsMarkdown;
}
/**
@@ -38,9 +43,25 @@ class MarkdownExtension extends \Twig_Extension
{
return [
new TwigFilter('md2html', [$this, 'markdownToHtml'], ['is_safe' => ['html']]),
new TwigFilter('desc2html', [$this, 'timesheetContent'], ['is_safe' => ['html']]),
];
}
/**
* Transforms the timesheet description content into HTML.
*
* @param string $content
* @return string
*/
public function timesheetContent(string $content): string
{
if ($this->timesheetIsMarkdown) {
return $this->markdown->toHtml($content, false);
}
return nl2br($content);
}
/**
* Transforms the given Markdown content into HTML
*
@@ -49,6 +70,6 @@ class MarkdownExtension extends \Twig_Extension
*/
public function markdownToHtml(string $content): string
{
return $this->markdown->toHtml($content);
return $this->markdown->toHtml($content, true);
}
}