Class: Gollum::Markup

Inherits:
Object
  • Object
show all
Defined in:
lib/smeagol/gollum/page.rb

Instance Method Summary collapse

Instance Method Details

Attempt to process the tag as a page link tag.

Parameters:

  • tag

    The String tag contents (the stuff inside the double brackets).

Returns:

  • the String HTML if the tag is a valid page link tag or nil if it is not.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/smeagol/gollum/page.rb', line 18

def process_page_link_tag(tag)
  parts = tag.split('|')
  parts.reverse! if @format == :mediawiki

  name, page_name = *parts.compact.map(&:strip)
  cname = @wiki.page_class.cname(page_name || name)

  if name =~ %r{^https?://} && page_name.nil?
    %{<a href="#{name}">#{name}</a>}
  else
    presence    = "absent"
    link_name   = cname
    page, extra = find_page_from_name(cname)
    if page
      link_name = @wiki.page_class.cname(page.name)
      presence  = "present"
    end
    link = ::File.join(@wiki.base_path, CGI.escape(link_name))

    # TODO: This is a temporary hack for posts until actual subdirs are supported.
    #       Also, this needs to be improved so /\d-/ does match if part of actual title.
    link = link.gsub(/(\d)-/, '\1/')

    %{<a class="internal #{presence}" href="#{link}#{extra}">#{name}</a>}
  end
end