Class: HTML::Pipeline::WikiLinkFilter
- Inherits:
-
Filter
- Object
- Filter
- HTML::Pipeline::WikiLinkFilter
- Defined in:
- lib/html/pipeline/wiki_link/wiki_link_filter.rb
Overview
An ‘HTML::Pipeline` filter class that detects wiki-style links and converts them to HTML links.
Instance Method Summary collapse
-
#call ⇒ String
Performs the translation and returns the updated text.
-
#initialize(doc, context = nil, result = nil) ⇒ WikiLinkFilter
constructor
Initializes a new instance of the ‘WikiLinkFilter` class.
Constructor Details
#initialize(doc, context = nil, result = nil) ⇒ WikiLinkFilter
Initializes a new instance of the ‘WikiLinkFilter` class.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/html/pipeline/wiki_link/wiki_link_filter.rb', line 17 def initialize(doc, context = nil, result = nil) super(doc, context, result) @base_url = '/' @space_replacement = '_' if context @base_url = context[:base_url] if context[:base_url] @space_replacement = context[:space_replacement] if context[:space_replacement] end unless @base_url.empty? || @base_url =~ /\/$/ @base_url += '/' end end |
Instance Method Details
#call ⇒ String
Performs the translation and returns the updated text.
36 37 38 39 40 41 42 43 |
# File 'lib/html/pipeline/wiki_link/wiki_link_filter.rb', line 36 def call html.gsub(/\[\[([^\]|]*)(\|([^\]]*))?\]\]/) do link = $1 desc = $3 ? $3 : $1 "<a href=\"#{to_link link}\">#{to_description desc}</a>" end end |