From b4828f4cf6405d27c01cc5be42334dd29a27285b Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Thu, 9 Oct 2014 13:33:38 +0200 Subject: Enable markdown pipeline filters from inside gitlab. --- lib/gitlab/markdown.rb | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index 17512a51658..d3e9bafb06c 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -70,14 +70,17 @@ module Gitlab insert_piece($1) end - # Context passed to the markdoqwn pipeline - markdown_context = { - asset_root: File.join(root_url, - Gitlab::Application.config.assets.prefix) - } - - result = HTML::Pipeline::Gitlab::MarkdownPipeline.call(text, - markdown_context) + # Used markdown pipelines in GitLab: + # GitlabEmojiFilter - performs emoji replacement. + # + # see https://gitlab.com/gitlab-org/html-pipeline-gitlab for more filters + filters = [ + HTML::Pipeline::Gitlab::GitlabEmojiFilter + ] + + markdown_pipeline = HTML::Pipeline::Gitlab.new(filters).pipeline + + result = markdown_pipeline.call(text) text = result[:output].to_html(save_with: 0) allowed_attributes = ActionView::Base.sanitized_allowed_attributes -- cgit v1.2.1 From 4149fc24cfe4ffa2d0d950e7f930529a05899b7c Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Fri, 10 Oct 2014 12:51:00 +0200 Subject: Bump html-pipeline-gitlab gem version --- Gemfile.lock | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index babb23ed606..517466f3d1a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -241,9 +241,11 @@ GEM html-pipeline (1.11.0) activesupport (>= 2) nokogiri (~> 1.4) - html-pipeline-gitlab (0.1.0) - gitlab_emoji (~> 0.0.1.1) + html-pipeline-gitlab (0.1.4) + actionpack (~> 4) + gitlab_emoji (~> 0.0.1) html-pipeline (~> 1.11.0) + sanitize (~> 2.1) http_parser.rb (0.5.3) httparty (0.13.0) json (~> 1.8) -- cgit v1.2.1 From 2ea166fc338f95cb9f6db1c61426dce4b2cfd8e1 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Fri, 10 Oct 2014 17:31:47 +0200 Subject: Make sure relative url and asset_host are honored, specs. --- Gemfile.lock | 2 +- lib/gitlab/markdown.rb | 7 ++++++- spec/helpers/gitlab_markdown_helper_spec.rb | 14 +++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 517466f3d1a..a9b71fec133 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -241,7 +241,7 @@ GEM html-pipeline (1.11.0) activesupport (>= 2) nokogiri (~> 1.4) - html-pipeline-gitlab (0.1.4) + html-pipeline-gitlab (0.1.5) actionpack (~> 4) gitlab_emoji (~> 0.0.1) html-pipeline (~> 1.11.0) diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index d3e9bafb06c..ddcce7557a0 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -78,9 +78,14 @@ module Gitlab HTML::Pipeline::Gitlab::GitlabEmojiFilter ] + markdown_context = { + asset_root: Gitlab.config.gitlab.url, + asset_host: Gitlab::Application.config.asset_host + } + markdown_pipeline = HTML::Pipeline::Gitlab.new(filters).pipeline - result = markdown_pipeline.call(text) + result = markdown_pipeline.call(text, markdown_context) text = result[:output].to_html(save_with: 0) allowed_attributes = ActionView::Base.sanitized_allowed_attributes diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index 15033f07432..26908abc30a 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -576,9 +576,21 @@ describe GitlabMarkdownHelper do end it "should generate absolute urls for emoji" do - markdown(":smile:").should include("src=\"#{url_helper('emoji/smile')}") + markdown(":smile:").should include("src=\"http://localhost/assets/emoji/smile.png") end + it "should generate absolute urls for emoji if relative url is present" do + Gitlab.config.gitlab.stub(:url).and_return('http://localhost/gitlab/root') + markdown(":smile:").should include("src=\"http://localhost/gitlab/root/assets/emoji/smile.png") + end + + it "should generate absolute urls for emoji if asset_host is present" do + Gitlab::Application.config.stub(:asset_host).and_return("https://cdn.example.com") + ActionView::Base.any_instance.stub_chain(:config, :asset_host).and_return("https://cdn.example.com") + markdown(":smile:").should include("src=\"https://cdn.example.com/assets/emoji/smile.png") + end + + it "should handle relative urls for a file in master" do actual = "[GitLab API doc](doc/api/README.md)\n" expected = "

GitLab API doc

\n" -- cgit v1.2.1