Skip to content

Instantly share code, notes, and snippets.

@jobee
Last active August 10, 2016 11:30
Show Gist options
  • Save jobee/42b3ce7464cf0c9efed06f051ff46117 to your computer and use it in GitHub Desktop.
Save jobee/42b3ce7464cf0c9efed06f051ff46117 to your computer and use it in GitHub Desktop.
Creating your own Markdown parser for Fluid templates in Flow / Neos applications
{
"require": {
"typo3/neos": "*",
"erusev/parsedown": "~1.6"
}
}
<?php
namespace Vendor\Name\ViewHelpers\Format;
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* ViewHelper rendering the given string through parsedown
* GitHub: https://github.com/erusev/parsedown
*/
class MarkdownViewHelper extends AbstractViewHelper
{
/**
* @var boolean
*/
protected $escapeChildren = false;
/**
* @var boolean
*/
protected $escapeOutput = false;
/**
* @param string $value The given markdown string
* @return string Returns the rendered html string
*/
public function render($value = null)
{
if ($value === null) {
$value = $this->renderChildren();
}
$parsedown = new \Parsedown();
return $parsedown->text($value);
}
}
<div>
{yourMarkdownString -> vendor.name:format.markdown()}
</div>
TYPO3:
Flow:
object:
excludeClasses:
# disable reflection for non-flow packages
# since Flow 3.0+ this is the default behaviour
'erusev.parsedown': ['.*']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment