Last active
August 10, 2016 11:30
-
-
Save jobee/42b3ce7464cf0c9efed06f051ff46117 to your computer and use it in GitHub Desktop.
Creating your own Markdown parser for Fluid templates in Flow / Neos applications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"typo3/neos": "*", | |
"erusev/parsedown": "~1.6" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
{yourMarkdownString -> vendor.name:format.markdown()} | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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