in _plugins/regex_filter.rb [24:115]
def refactorURL(input, reg_str, site, pages, availablePages, mergePage, currentPage)
if input == nil
return nil
end
$pid = "id-undefined"
if currentPage['title'] != nil
$pid = currentPage['title'].downcase.delete('/')
$pid.gsub!(/\s+/, '-')
end
input.gsub!("id=\"", "id=\"internalLink_"+$pid+"_")
input.gsub!(" target=\"_blank\"", "")
re = Regexp.new reg_str, Regexp::MULTILINE
input.gsub(re) {
$newLink = "#"
$match = Regexp.last_match.captures[0]
if $match.start_with?('http')
$newLink = $match
elsif $match.start_with?('#')
$newLink = "#internalLink_"+$pid+"_"+($match.gsub! '#', '')
else
if $match =~ /
$match = $match[/[^
end
if $match.start_with?('./')
$match = currentPage['dir']+"/"+$match[2, $match.length]
elsif !($match.start_with?('/'))
$match = currentPage['dir']+"/"+$match
end
if $match.end_with?('/')
$match = $match+"index.html"
end
$pageOutOfScope = true;
for page in availablePages
if (page['url'] == $match)
$pageOutOfScope = false;
$current_pid = page['title'].downcase.delete('/')
$current_pid.gsub!(/\s+/, '-')
$newLink = "#contentsLink-"+$current_pid
end
end
if $pageOutOfScope
$notFoundPrefix = true
for prefix in site['pdf-rewrite-prefixes']
if $match.start_with?(prefix[0])
$notFoundPrefix = false
$newLink = site['pdf-default-base-url']+prefix[1]+$match[prefix[0].length, $match.length]
end
end
if $notFoundPrefix
$newLink = site['pdf-default-base-url']+site['pdf-default-versioned-url-subpath']+$match
puts "PDF link to "+$match+" in "+currentPage['path']+" has unknown prefix, routing to "+$newLink
end
end
end
"href=\""+$newLink+"\""
}
end