Last active
December 20, 2015 06:49
-
-
Save tomoyamkung/6089255 to your computer and use it in GitHub Desktop.
[Ruby]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
#! 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