Last active
July 13, 2016 12:29
-
-
Save matthewpizza/811738c36877f41fe664 to your computer and use it in GitHub Desktop.
Using Jetpack’s Markdown with Timber https://matthewspencer.me/notes/using-jetpacks-markdown-with-timber
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 | |
/** | |
* Twig filter for converting Markdown | |
* | |
* @uses Jetpack | |
* @uses WPCom_Markdown | |
*/ | |
add_filter( 'get_twig', function ( $twig ) { | |
$twig->addFilter( new Twig_SimpleFilter( 'markdown', function ( $text ) { | |
if ( ! class_exists( 'Jetpack' ) || ! Jetpack::is_module_active( 'markdown' ) ) { | |
return $text; | |
} | |
jetpack_require_lib( 'markdown' ); | |
return WPCom_Markdown::get_instance()->transform( $text, array( 'unslash' => false ) ); | |
} ) ); | |
return $twig; | |
} ); |
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
{{ post.post_title|markdown }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment