Last active
December 13, 2015 17:49
-
-
Save chiastolite/4951207 to your computer and use it in GitHub Desktop.
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
# -*- coding:utf-8 -*- | |
require 'bundler/setup' | |
Bundler.require | |
require 'redcarpet' | |
class DenDen < Redcarpet::Render::HTML | |
def normal_text text | |
text.gsub(/\^([^\^]+?)\^/) do |_| | |
"<span class='tcy'>#{$1}</span>" | |
end.gsub(%r!{([^|]+)\|(.+)}!) do |_| | |
"<ruby>#{$1}<rt>#{$2}</rt></ruby>" | |
end | |
end | |
end | |
markdown = Redcarpet::Markdown.new(DenDen, no_intra_emphasis: true,fenced_code_blocks: true,autolink: true,tables: true, with_toc_data: true) | |
# markdown.render('昭和^53^年') | |
# => <p>昭和<span class='tcy'>53</span>年</p> | |
# markdown.render('{電子出版|でんししゅっぱん}') | |
# => <p><ruby>電子出版<rt>でんししゅっぱん</rt></ruby></p> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment