mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-23 11:36:09 +10:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -27,11 +27,7 @@
|
||||
.col-md-8
|
||||
.documentation-index
|
||||
= preserve do
|
||||
- readme_text = File.read(Rails.root.join("doc", "README.md"))
|
||||
- text = readme_text.dup
|
||||
- readme_text.scan(/\]\(([^(]+)\)/) { |match| text.gsub!(match.first, "help/#{match.first}") }
|
||||
= markdown text
|
||||
|
||||
= markdown(@help_index)
|
||||
.col-md-4
|
||||
.panel.panel-default
|
||||
.panel-heading
|
||||
|
||||
Reference in New Issue
Block a user