Created
August 31, 2012 22:02
-
-
Save BaylorRae/3559768 to your computer and use it in GitHub Desktop.
Source code for: http://baylorrae.com/how-i-use-markdown-with-wordpress/
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 characters
<?php | |
function markdown_filter($data, $post) { | |
// change this to match your heroku app url | |
$ch = curl_init('http://radiant-stone-4578.heroku.com/parse'); | |
curl_setopt_array($ch, array( | |
// don't print the result when done | |
CURLOPT_RETURNTRANSFER => true, | |
// use a post request and pass on the content | |
CURLOPT_POST => true, | |
CURLOPT_POSTFIELDS => 'markdown=' . urlencode($data['post_content']) | |
)); | |
// grab the parsed content | |
$parsed = curl_exec($ch); | |
curl_close($ch); | |
// back up the original markdown | |
$data['post_content_filtered'] = $data['post_content']; | |
// save the new parsed html | |
$data['post_content'] = $parsed; | |
return $data; | |
} | |
function get_markdown($content, $id) { | |
$post = get_post($id); | |
// make sure the post has content saved in post_content_filtered | |
if( $post && !empty($post->post_content_filtered) ) | |
$content = $post->post_content_filtered; | |
return $content; | |
} | |
/** | |
* I'm not entirely sure why this is done | |
* it was used in the "Markdown on Save" plugin | |
* and I kept it in case it was needed | |
* | |
* @author Mark Jaquith | |
*/ | |
function get_markdown_filtered($content, $id) { | |
return $content; | |
} | |
// on post save/update | |
add_filter( 'wp_insert_post_data' , 'markdown_filter' , '99', 2 ); | |
// when editing a post | |
add_filter('edit_post_content', 'get_markdown', '99', 2); | |
// when editing post_content_filtered | |
add_filter('edit_post_content_filtered', 'get_markdown_filtered', '99', 2); | |
?> |
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 characters
require 'rubygems' | |
require "sinatra" | |
require "redcarpet" | |
get "/" do | |
"I'm alive, I'm alive, I'm ... why are you not excited?" | |
end | |
post "/parse" do | |
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, | |
:autolink => true, :space_after_headers => true, :fenced_code_blocks => true, :no_intra_emphasis => true) | |
markdown.render(params[:markdown]) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment