Class: LinkRewriterFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Defined in:
lib/link-rewriter-filter.rb

Constant Summary collapse

/(.+?)\.md$/

Instance Method Summary collapse

Instance Method Details

#callObject


6
7
8
9
10
11
12
13
14
# File 'lib/link-rewriter-filter.rb', line 6

def call
  prefix = context[:link_rewriter_prefix] || '/docs/'
  doc.search('a').each do |a|
    next if a['href'].nil? || a['href'].blank?
    a['href'] = "#{prefix}#{$1}/" if a['href'] =~ LINK_REGEX
  end

  doc
end