Class: Jekyll::Converters::Ruby
- Inherits:
-
Converter
- Object
- Converter
- Jekyll::Converters::Ruby
- Defined in:
- lib/jekyll/converters/ruby.rb
Constant Summary collapse
- RUBY_PATTERN =
%r( { (?<kanji>[^{}|]*) \| (?<kana>[^{}]*) } )x
Instance Method Summary collapse
Instance Method Details
#convert(content) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jekyll/converters/ruby.rb', line 25 def convert(content) content.gsub(RUBY_PATTERN) do |match| kanji, *kanas = match.slice(1...-1).split('|') return "<ruby>#{kanji}<rt></rt></ruby>" if kanas.empty? pairs = [] kanas.each_with_index do |kana, i| if i == kanas.size - 1 pairs << [kanji.slice(i..-1), kana] else pairs << [kanji.slice(i), kana] end end "<ruby>#{pairs.map { |k, kana| "#{k}<rt>#{kana}</rt>" }.join}</ruby>" end end |
#matches(_ext) ⇒ Object
18 19 20 |
# File 'lib/jekyll/converters/ruby.rb', line 18 def matches(_ext) true end |
#output_ext(_ext) ⇒ Object
22 23 |
# File 'lib/jekyll/converters/ruby.rb', line 22 def output_ext(_ext) end |