diff options
| -rw-r--r-- | app/controllers/help_controller.rb | 18 | ||||
| -rw-r--r-- | app/views/help/index.html.haml | 6 |
2 files changed, 19 insertions, 5 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 diff --git a/app/views/help/index.html.haml b/app/views/help/index.html.haml index f492aaf4c0a..ab7ed1b5d95 100644 --- a/app/views/help/index.html.haml +++ b/app/views/help/index.html.haml @@ -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 |
