Skip to content

Instantly share code, notes, and snippets.

@daltonrooney
Last active May 22, 2020 17:15
Show Gist options
  • Select an option

  • Save daltonrooney/ab170a14e938a29562d834004ca08436 to your computer and use it in GitHub Desktop.

Select an option

Save daltonrooney/ab170a14e938a29562d834004ca08436 to your computer and use it in GitHub Desktop.
Useful HTML filters for Timber Twig (widows and markdown support)
// Requires WP-Markdown Example {{post.title|md2html}} {{post.description|html2md}}
if ( function_exists('wpmarkdown_markdown_to_html') && function_exists('wpmarkdown_html_to_markdown') ) {
add_filter( 'timber/twig', 'md_add_to_twig' );
function md_add_to_twig( $twig ) {
$twig->addFilter( new Timber\Twig_Filter( 'md2html', 'md2html' ) );
$twig->addFilter( new Timber\Twig_Filter( 'html2md', 'html2md' ) );
return $twig;
}
function md2html($content) {
return wpmarkdown_markdown_to_html($content);
}
function html2md($content) {
return wpmarkdown_html_to_markdown($content);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment