Skip to content

Instantly share code, notes, and snippets.

@japborst
Last active August 29, 2015 14:08
Show Gist options
  • Save japborst/89a0dd78903111285268 to your computer and use it in GitHub Desktop.
Save japborst/89a0dd78903111285268 to your computer and use it in GitHub Desktop.
<?php
// article.php located at /themes/<theme>/article.php
// ...
// replace
echo article_markdown();
// with
echo custom_markdown();
// ...
?>
<?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