class Mato::HtmlFilters::TokenLink

Attributes

builder[R]

@return [Proc]

pattern[R]

@return [Regexp]

Public Class Methods

new(pattern, &builder) click to toggle source

@param [Regexp] pattern @param [Procc] builder link builder that takes

# File lib/mato/html_filters/token_link.rb, line 18
def initialize(pattern, &builder)
  @pattern = pattern
  @builder = builder
end

Public Instance Methods

call(doc) click to toggle source

@param [Nokogiri::HTML4::DocumentFragment] doc

# File lib/mato/html_filters/token_link.rb, line 24
def call(doc)
  doc.xpath('.//text()').each do |text_node|
    next if has_ancestor?(text_node, 'a', 'code')

    text_node.replace(text_node.content.gsub(pattern, &builder))
  end
end