Skip to content

Instantly share code, notes, and snippets.

@lancejpollard
Created February 15, 2012 19:05
Show Gist options
  • Save lancejpollard/1838200 to your computer and use it in GitHub Desktop.
Save lancejpollard/1838200 to your computer and use it in GitHub Desktop.
Github Flavored Markdown in Node.js
cake markdown
{spawn, exec} = require('child_process')
task 'markdown', ->
command = spawn 'ruby', ["./to-markdown.rb"]
command.stdout.setEncoding('utf8')
command.stdout.on 'data', (data) ->
console.log data #=> <p><strong>Hello World</strong></p>
command.stdout.setEncoding('utf8')
command.stderr.on 'data', (data) ->
console.log "error"
console.log data.toString().trim()
command.stdin.write JSON.stringify(input: "**Hello World**")
command.stdin.end()
require 'rubygems'
require 'redcarpet'
require 'json'
STDOUT.sync = true
io = STDOUT
json = JSON.parse(STDIN.read)
input = json.delete("input")
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true, :fenced_code_blocks => true)
io.write markdown.render(input)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment