Last active
May 22, 2020 17:15
-
-
Save daltonrooney/ab170a14e938a29562d834004ca08436 to your computer and use it in GitHub Desktop.
Revisions
-
daltonrooney revised this gist
May 22, 2020 . 1 changed file with 21 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,29 @@ <?php add_filter( 'timber/twig', 'add_to_twig' ); function add_to_twig( $twig ) { $twig->addFilter( new Timber\Twig_Filter( 'noWidows', 'twigNoWidow' ) ); return $twig; } function twigNoWidow($text = "", $numberOfWords = 1, $outputRaw = true ) { $tags = "a|span|i|b|em|strong|acronym|caps|sub|sup|abbr|big|small|code|cite|tt"; // Taken from https://github.com/davethegr8/cakephp-typogrify-helper/blob/master/views/helpers/typogrify.php $regex = "/([^\s])\s+(((<($tags)[^>]*>)*\s*[^\s<>]+)(<\/($tags)>)*[^\s<>]*\s*(<\/(p|h[1-6]|li)>|$))/i"; $string = $text; for ($i = 0; $i < $numberOfWords; $i++) { $string = preg_replace($regex, '$1 $2', $string); } return $string; } if ( function_exists('wpmarkdown_markdown_to_html') && function_exists('wpmarkdown_html_to_markdown') ) { add_filter( 'timber/twig', 'md_add_to_twig' ); // Requires WP-Markdown // Usage {{post.title|md2html}} {{post.description|html2md}} function md_add_to_twig( $twig ) { $twig->addFilter( new Timber\Twig_Filter( 'md2html', 'md2html' ) ); -
daltonrooney revised this gist
May 8, 2020 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,7 @@ <?php // Requires WP-Markdown // Usage {{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' ); -
daltonrooney created this gist
May 8, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ // 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); } }