class HTML::Pipeline::CustomLinksFilter
Constants
- IGNORE_PARENTS
Don't look for links in text nodes that are children of these elements
- LF_REGEXP
- LF_TITLE
- WP_REGEXP
- WP_TITLE
Public Instance Methods
call()
click to toggle source
# File lib/html/pipeline/custom_links_filter.rb, line 18 def call doc.search('.//text()').each do |node| content = node.to_html next if !content.include?('[[') next if has_ancestor?(node, IGNORE_PARENTS) html = content html = process_internal_wiki_links html html = process_wikipedia_links html next if html == content node.replace(html) end doc end
process_internal_wiki_links(text)
click to toggle source
# File lib/html/pipeline/custom_links_filter.rb, line 32 def process_internal_wiki_links(text) base_url = "//#{context[:host]}/wiki" text.gsub(LF_REGEXP) do word = $1 slug = word.parameterize "<a href=\"#{base_url}/#{slug}\" title=\"#{LF_TITLE}\">#{word}</a>" end end
process_wikipedia_links(text)
click to toggle source
# File lib/html/pipeline/custom_links_filter.rb, line 41 def process_wikipedia_links(text) text.gsub(WP_REGEXP) do word = $1 parts = word.split(":") parts.shift if %w(de en es eo wikt).include?(parts.first) "<a href=\"https://fr.wikipedia.org/wiki/#{word}\" title=\"#{WP_TITLE}\")>#{parts.join ':'}</a>" end end