Skip to content

Instantly share code, notes, and snippets.

@chiastolite
Last active December 13, 2015 17:49
Show Gist options
  • Save chiastolite/4951207 to your computer and use it in GitHub Desktop.
Save chiastolite/4951207 to your computer and use it in GitHub Desktop.
# -*- 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