News: Render as markdown
This commit is contained in:
parent
a309d873a7
commit
620c9a02bb
|
@ -73,7 +73,7 @@
|
|||
</div>
|
||||
|
||||
<div class="panel-body">
|
||||
{{ news.text|raw|nl2br }}
|
||||
{{ news.text|raw|markdown(false) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
{% endif %}
|
||||
|
||||
<div class="panel-body">
|
||||
{{ news.text|raw|nl2br }}
|
||||
{{ news.text|raw|markdown(false) }}
|
||||
</div>
|
||||
|
||||
<div class="panel-footer text-muted">
|
||||
|
|
|
@ -34,10 +34,16 @@ class Markdown extends TwigExtension
|
|||
|
||||
/**
|
||||
* @param string $text
|
||||
* @param bool $escapeHtml
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render(string $text): string
|
||||
public function render(string $text, bool $escapeHtml = true): string
|
||||
{
|
||||
return $this->renderer->text(htmlspecialchars($text));
|
||||
if ($escapeHtml) {
|
||||
$text = htmlspecialchars($text);
|
||||
}
|
||||
|
||||
return $this->renderer->text($text);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,4 +41,23 @@ class MarkdownTest extends ExtensionTest
|
|||
$extension = new Markdown($renderer);
|
||||
$this->assertEquals($return, $extension->render('Lorem *"Ipsum"*'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Engelsystem\Renderer\Twig\Extensions\Markdown::render
|
||||
*/
|
||||
public function testRenderHtml()
|
||||
{
|
||||
/** @var Parsedown|MockObject $renderer */
|
||||
$renderer = $this->createMock(Parsedown::class);
|
||||
|
||||
$input = '<i>**test**</i>';
|
||||
$return = '<p><strong><i>**test**</i></strong></p>';
|
||||
$renderer->expects($this->once())
|
||||
->method('text')
|
||||
->with($input)
|
||||
->willReturn($return);
|
||||
|
||||
$extension = new Markdown($renderer);
|
||||
$this->assertEquals($return, $extension->render($input, false));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue