Created
February 15, 2012 19:05
-
-
Save lancejpollard/1838200 to your computer and use it in GitHub Desktop.
Github Flavored Markdown in Node.js
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
cake 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
{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() |
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
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