Skip to content

Commit 2e35021

Browse files
author
Robert Speicher
committed
Merge branch 'fix-double-brackets-in-wiki-markdown' into 'master'
Fix double brackets being linkified in wiki markdown See merge request gitlab-org/gitlab-ce!18524
2 parents 076ab2e + 1b530f9 commit 2e35021

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Fix double-brackets being linkified in wiki markdown
3+
merge_request: 18524
4+
author: brewingcode
5+
type: fixed

lib/banzai/filter/gollum_tags_filter.rb

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class GollumTagsFilter < HTML::Pipeline::Filter
5858

5959
def call
6060
doc.search(".//text()").each do |node|
61+
# Do not perform linking inside <code> blocks
62+
next unless node.ancestors('code').empty?
63+
6164
# A Gollum ToC tag is `[[_TOC_]]`, but due to MarkdownFilter running
6265
# before this one, it will be converted into `[[<em>TOC</em>]]`, so it
6366
# needs special-case handling

spec/features/projects/wiki/markdown_preview_spec.rb

+23
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,27 @@ def create_wiki_page(path)
155155
end
156156
end
157157
end
158+
159+
it "does not linkify double brackets inside code blocks as expected" do
160+
click_link 'New page'
161+
page.within '#modal-new-wiki' do
162+
fill_in :new_wiki_path, with: 'linkify_test'
163+
click_button 'Create page'
164+
end
165+
166+
page.within '.wiki-form' do
167+
fill_in :wiki_content, with: <<-HEREDOC
168+
`[[do_not_linkify]]`
169+
```
170+
[[also_do_not_linkify]]
171+
```
172+
HEREDOC
173+
click_on "Preview"
174+
end
175+
176+
expect(page).to have_content("do_not_linkify")
177+
178+
expect(page.html).to include('[[do_not_linkify]]')
179+
expect(page.html).to include('[[also_do_not_linkify]]')
180+
end
158181
end

spec/lib/banzai/filter/gollum_tags_filter_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@
9191
expect(doc.at_css('a').text).to eq 'link-text'
9292
expect(doc.at_css('a')['href']).to eq expected_path
9393
end
94+
95+
it "inside back ticks will be exempt from linkification" do
96+
doc = filter('<code>[[link-in-backticks]]</code>', project_wiki: project_wiki)
97+
98+
expect(doc.at_css('code').text).to eq '[[link-in-backticks]]'
99+
end
94100
end
95101

96102
context 'table of contents' do

0 commit comments

Comments
 (0)