Class: Markdown2Html::LinkFilter
- Inherits:
-
Object
- Object
- Markdown2Html::LinkFilter
- Defined in:
- lib/markdown2html/link_filter.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(source, repository) ⇒ LinkFilter
constructor
A new instance of LinkFilter.
- #page_name_to_path(page_name) ⇒ Object
Constructor Details
#initialize(source, repository) ⇒ LinkFilter
Returns a new instance of LinkFilter.
3 4 5 6 |
# File 'lib/markdown2html/link_filter.rb', line 3 def initialize(source, repository) @source = source @repository = repository end |
Instance Method Details
#call ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/markdown2html/link_filter.rb', line 8 def call @result = @source.gsub(/\[\[.*\]\]/) do |page_name| page_name.gsub!(/[\[\]]/, '') link = page_name_to_path(page_name) "<a href=\"#{link}\">#{page_name}</a>" end if @repository @result.gsub!(/"(https:\/\/github.com\/#{@repository}\/wiki\/)(.*)"/) do |explicit_link| url, path = $1, $2 next explicit_link if path =~ /^_pages/ explicit_link.gsub!(url, '') explicit_link.gsub!(path, page_name_to_path(path)) end end @result end |
#page_name_to_path(page_name) ⇒ Object
29 30 31 |
# File 'lib/markdown2html/link_filter.rb', line 29 def page_name_to_path(page_name) "#{page_name.downcase.gsub(/\s/,'-').gsub(':', '%3A')}.html" end |