Sha256: 6076751a079a54992fce55350e706259b024f4be9c41702821570ec92f1407ff
Contents?: true
Size: 498 Bytes
Versions: 1
Compression:
Stored size: 498 Bytes
Contents
require 'html/pipeline' class LinkRewriterFilter < HTML::Pipeline::MarkdownFilter VERSION = '0.0.1' LINK_REGEX = /(.+?)\.md$/ def initialize(text, context = nil, result = nil) @prefix = context[:link_rewriter_prefix] || '/docs/' super text, context, result end def call html = super doc = Nokogiri::HTML(html) doc.search("a").each do |a| next if a['href'].nil? a["href"] = "#{@prefix}#{$1}/" if a['href'] =~ LINK_REGEX end doc.to_s end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
link-rewriter-filter-0.0.1 | lib/link-rewriter-filter.rb |