Skip to content

Instantly share code, notes, and snippets.

@matthewpizza
Last active July 13, 2016 12:29
Show Gist options
  • Save matthewpizza/811738c36877f41fe664 to your computer and use it in GitHub Desktop.
Save matthewpizza/811738c36877f41fe664 to your computer and use it in GitHub Desktop.
<?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;
} );
{{ post.post_title|markdown }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment