Last active
August 29, 2015 14:08
-
-
Save japborst/89a0dd78903111285268 to your computer and use it in GitHub Desktop.
This file contains 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 | |
// article.php located at /themes/<theme>/article.php | |
// ... | |
// replace | |
echo article_markdown(); | |
// with | |
echo custom_markdown(); | |
// ... | |
?> |
This file contains 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 | |
// functions.php located at /themes/<theme>/functions.php | |
// ... | |
function custom_markdown() { | |
// if you just want the raw content you saved | |
$post = new Markdown; | |
$post = $post->transform(Registry::prop('article', 'html')); | |
// Create new matching function | |
function _handle_match($match) { | |
// Requires pre and code tag to be both on the same line for this to work | |
return '<pre'.$match[1].'><code'.$match[2].'>'.htmlspecialchars($match[3]).'</code></pre>'; | |
} | |
// Encode whatever's in the <pre><code> to special characters | |
$post = preg_replace_callback('/<pre(.+?)><code(.+?)>(.+?)<\/code><\/pre>/s', '_handle_match', $post); | |
// Output converted post | |
return $post; | |
} | |
// ... | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment