Created
March 13, 2017 04:31
-
-
Save AugustMiller/c1be037c0e063e0c0538ee0262970d75 to your computer and use it in GitHub Desktop.
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
<? namespace Craft; | |
class HelpersPlugin extends BasePlugin | |
{ | |
public function getName() | |
{ | |
return Craft::t('Helpers'); | |
} | |
public function getVersion() | |
{ | |
return '1.0'; | |
} | |
public function getDeveloper() | |
{ | |
return 'oof. Studio'; | |
} | |
public function getDeveloperUrl() | |
{ | |
return 'http://oof.studio/'; | |
} | |
public function hasCpSection() | |
{ | |
return false; | |
} | |
public function addTwigExtension() | |
{ | |
Craft::import('plugins.helpers.twigextensions.HelpersTwigExtension'); | |
return new HelpersTwigExtension(); | |
} | |
} |
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 Craft; | |
class HelpersTwigExtension extends \Twig_Extension | |
{ | |
public function getName() | |
{ | |
return 'Helpers Twig Extension'; | |
} | |
public function getFilters() | |
{ | |
$filters = []; | |
$methods = [ | |
'mdline' => 'markdownSingleLine' | |
]; | |
foreach ($methods as $key => $method) { | |
$filters[$key] = new \Twig_Filter_Method($this, $method); | |
} | |
return $filters; | |
} | |
/* | |
* Twig proxy for Craft's built-in single-line markdown parsing function | |
*/ | |
public function markdownSingleLine($md) | |
{ | |
return StringHelper::parseMarkdownLine($md); | |
} | |
} |
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
Standard markdown still works: | |
{{ entry.markdownField | md }} {# or `markdown` #} | |
This adds the following filter, which strips out block-level tags: | |
{{ entry.markdownField | mdline }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Plugin structure should look like this: