allow markdown in timesheet descriptions (#296)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user