Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-09-23 01:26:51 +0300
committerRobert Speicher <rspeicher@gmail.com>2015-09-23 01:26:51 +0300
commit64e0dfa5306aebdedeb65f2a6db95f4d2314f143 (patch)
treeaf0d046826e52322a8fa4ae9d0c4d1743a737c57 /app/controllers/help_controller.rb
parentc551c81e28418c67fb398d6efb2183588c09f862 (diff)
Prevent double-prefixing of help page paths
Prior, because the link "api/README.md" was matched twice, the first link became "help/help/api/README.md". Now we do a negative lookahead to make sure the link doesn't start with `help/`. This fix is still not ideal, see TODO note.
Diffstat (limited to 'app/controllers/help_controller.rb')
-rw-r--r--app/controllers/help_controller.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb
index ad00948da51..7283c4f4a4c 100644
--- a/app/controllers/help_controller.rb
+++ b/app/controllers/help_controller.rb
@@ -4,6 +4,8 @@ class HelpController < ApplicationController
layout 'help'
def index
+ @help_index = File.read(Rails.root.join('doc', 'README.md'))
+ prefix_help_links!(@help_index)
end
def show
@@ -57,6 +59,22 @@ class HelpController < ApplicationController
params
end
+ # Prefix links in a Markdown document with `help/` unless they already have
+ # been
+ #
+ # TODO (rspeicher): This should be a pipeline filter that only gets included
+ # for help pages, and it should operate on the Nokogiri doc to be more robust.
+ #
+ # text - Markdown String
+ #
+ # Modifies `text` in-place
+ def prefix_help_links!(text)
+ # Match text inside a Markdown link unless it already starts with `help/`
+ #
+ # See http://rubular.com/r/nwwhzH6Z8X
+ text.gsub!(%r{(\]\()(?!help\/)([^\)\(]+)(\))}x, '\1help/\2\3')
+ end
+
PATH_SEPS = Regexp.union(*[::File::SEPARATOR, ::File::ALT_SEPARATOR].compact)
# Taken from ActionDispatch::FileHandler