class HTML::Pipeline::RubyMarkup::Transformer

Constants

RubyMarkupInsideCodePattern
RubyTagPattern

Matching [漢字(かんじ)] or [漢字(かんじ)](url)

Attributes

content[R]

Public Class Methods

new(content) click to toggle source
# File lib/html/pipeline/ruby_markup/transformer.rb, line 14
def initialize(content)
  @content = content
end
run(content) click to toggle source
# File lib/html/pipeline/ruby_markup/transformer.rb, line 10
def self.run(content)
  new(content).run
end

Public Instance Methods

run() click to toggle source
# File lib/html/pipeline/ruby_markup/transformer.rb, line 18
def run
  transform_ruby_markups!
end

Private Instance Methods

transform_ruby_markups!() click to toggle source
# File lib/html/pipeline/ruby_markup/transformer.rb, line 41
def transform_ruby_markups!
  traverser.each do |line|
    next if traverser.in_codeblock?
    next if line.match?(RubyMarkupInsideCodePattern)

    matches = line.scan(RubyTagPattern)

    if !matches.empty?
      matches.each do |word, reading, uri|
        ruby_element = Element.new(word, reading, uri)
        line.sub!(ruby_element.original, ruby_element.to_html)
      end
    end
  end.join
end
traverser() click to toggle source
# File lib/html/pipeline/ruby_markup/transformer.rb, line 37
def traverser
  @traverser ||= content.empty? ? [] : MarkdownTraverser.new(content)
end