markdown = $parser; $this->timesheetIsMarkdown = $timesheetAsMarkdown; } /** * @return TwigFilter[] */ public function getFilters() { 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($content): string { if (empty($content)) { return ''; } if ($this->timesheetIsMarkdown) { return $this->markdown->toHtml($content, false); } return nl2br($content); } /** * Transforms the given Markdown content into HTML * * @param string $content * @return string */ public function markdownToHtml(string $content): string { return $this->markdown->toHtml($content, true); } }