Skip to content

Instantly share code, notes, and snippets.

@tomoyamkung
Last active December 20, 2015 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomoyamkung/6089255 to your computer and use it in GitHub Desktop.
Save tomoyamkung/6089255 to your computer and use it in GitHub Desktop.
[Ruby]Markdownをパースするスニペット
#! ruby
#-*- encoding: utf-8 -*-
module MarkDownParser
require 'redcarpet'
def parse_with_redcarpet(str)
return Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(str)
end
module_function :parse_with_redcarpet
end
if __FILE__ == $0
require 'test/unit'
class MarkDownParserTest < Test::Unit::TestCase
include MarkDownParser
def test_parse
str = '# line1'
assert_equal("<h1>line1</h1>\n", MarkDownParser.parse_with_redcarpet(str))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment