Commit ace8b0ab authored by Douwe Maan's avatar Douwe Maan

Merge branch 'ben.boeckel/gitlab-ce-fixup-links-in-generic-docs' into 'master'

Fix relative links in other markup formats

_Originally opened at !1845 by @ben.boeckel._

- - -

The RelativeLinkFilter was not applied to other document formats, e.g.,
reStructuredText, so links from the Files view or the Project view did
not work.

Fixes #3533.

See merge request !2798
parents 0f2dc6a7 e919b5a4
...@@ -17,6 +17,7 @@ v 8.5.0 (unreleased) ...@@ -17,6 +17,7 @@ v 8.5.0 (unreleased)
set it up set it up
- API: Added "merge_requests/:merge_request_id/closes_issues" (Gal Schlezinger) - API: Added "merge_requests/:merge_request_id/closes_issues" (Gal Schlezinger)
- Fix diff comments loaded by AJAX to load comment with diff in discussion tab - Fix diff comments loaded by AJAX to load comment with diff in discussion tab
- Fix relative links in other markup formats (Ben Boeckel)
- Whitelist raw "abbr" elements when parsing Markdown (Benedict Etzel) - Whitelist raw "abbr" elements when parsing Markdown (Benedict Etzel)
- Fix label links for a merge request pointing to issues list - Fix label links for a merge request pointing to issues list
- Don't vendor minified JS - Don't vendor minified JS
......
...@@ -212,8 +212,7 @@ module ApplicationHelper ...@@ -212,8 +212,7 @@ module ApplicationHelper
file_content file_content
end end
else else
GitHub::Markup.render(file_name, file_content). other_markup(file_name, file_content)
force_encoding(file_content.encoding).html_safe
end end
rescue RuntimeError rescue RuntimeError
simple_format(file_content) simple_format(file_content)
......
...@@ -78,6 +78,21 @@ module GitlabMarkdownHelper ...@@ -78,6 +78,21 @@ module GitlabMarkdownHelper
) )
end end
def other_markup(file_name, text)
Gitlab::OtherMarkup.render(
file_name,
text,
project: @project,
current_user: (current_user if defined?(current_user)),
# RelativeLinkFilter
project_wiki: @project_wiki,
requested_path: @path,
ref: @ref,
commit: @commit
)
end
# Return the first line of +text+, up to +max_chars+, after parsing the line # Return the first line of +text+, up to +max_chars+, after parsing the line
# as Markdown. HTML tags in the parsed output are not counted toward the # as Markdown. HTML tags in the parsed output are not counted toward the
# +max_chars+ limit. If the length limit falls within a tag's contents, then # +max_chars+ limit. If the length limit falls within a tag's contents, then
......
module Banzai
module Pipeline
class AsciidocPipeline < BasePipeline
def self.filters
[
Filter::RelativeLinkFilter
]
end
end
end
end
...@@ -31,9 +31,7 @@ module Gitlab ...@@ -31,9 +31,7 @@ module Gitlab
html = ::Asciidoctor.convert(input, asciidoc_opts) html = ::Asciidoctor.convert(input, asciidoc_opts)
if context[:project] html = Banzai.post_process(html, context)
html = Banzai.render(html, context.merge(pipeline: :asciidoc))
end
html.html_safe html.html_safe
end end
......
module Gitlab
# Parser/renderer for markups without other special support code.
module OtherMarkup
# Public: Converts the provided markup into HTML.
#
# input - the source text in a markup format
# context - a Hash with the template context:
# :commit
# :project
# :project_wiki
# :requested_path
# :ref
#
def self.render(file_name, input, context)
html = GitHub::Markup.render(file_name, input).
force_encoding(input.encoding)
html = Banzai.post_process(html, context)
html.html_safe
end
end
end
...@@ -293,6 +293,10 @@ describe ApplicationHelper do ...@@ -293,6 +293,10 @@ describe ApplicationHelper do
describe 'render_markup' do describe 'render_markup' do
let(:content) { 'Noël' } let(:content) { 'Noël' }
let(:user) { create(:user) }
before do
allow(helper).to receive(:current_user).and_return(user)
end
it 'should preserve encoding' do it 'should preserve encoding' do
expect(content.encoding.name).to eq('UTF-8') expect(content.encoding.name).to eq('UTF-8')
......
...@@ -42,22 +42,6 @@ module Gitlab ...@@ -42,22 +42,6 @@ module Gitlab
end end
end end
context "with project in context" do
let(:context) { { project: create(:project) } }
it "should filter converted input via HTML pipeline and return result" do
filtered_html = '<b>ASCII</b>'
allow(Asciidoctor).to receive(:convert).and_return(html)
expect(Banzai).to receive(:render)
.with(html, context.merge(pipeline: :asciidoc))
.and_return(filtered_html)
expect( render('foo', context) ).to eql filtered_html
end
end
def render(*args) def render(*args)
described_class.render(*args) described_class.render(*args)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment