Project

General

Profile

Defect #13723 » 0001-Fix-section-edit-links-inside-and-after-the-collapse.patch

Marius BĂLTEANU, 2026-06-16 23:52

View differences:

app/helpers/application_helper.rb
@heading_anchors = {}
@current_section = 0 if options[:edit_section_links]
parse_sections(text, project, obj, attr, only_path, options)
text = parse_non_pre_blocks(text, obj, macros, options) do |txt|
[:parse_wiki_links, :parse_redmine_links].each do |method_name|
send method_name, txt, project, obj, attr, only_path, options
end
end
parse_sections(text, project, obj, attr, only_path, options)
parse_headings(text, project, obj, attr, only_path, options)
if @parsed_headings.any?
test/helpers/application_helper_test.rb
end
end
def test_section_edit_links_with_collapse_macro
raw = <<~RAW
# Wiki
## Section A
collapsed section
{{collapse(View details...)
## Section B
}}
## Section C
RAW
@project = Project.find(1)
set_language_if_valid 'en'
with_settings :text_formatting => 'common_mark' do
result =
textilizable(
raw,
:edit_section_links =>
{:controller => 'wiki', :action => 'edit',
:project_id => '1', :id => 'Test'}
).delete("\n")
# Section B inside collapse macro should have section=3 edit link
assert_match(
Regexp.new(
'<div class="contextual heading-2" title="Edit this section" id="section-3">' \
'<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\\?section=3">' \
'<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-.*\\.svg#icon--edit"></use></svg>' \
'<span class="icon-label">Edit this section</span>' \
'</a></div>' \
'<a name="Section-B"></a>' \
'<h2 >Section B<a href="#Section-B" class="wiki-anchor">&para;</a></h2>'
),
result
)
# Section C after collapse macro should have section=4 edit link
assert_match(
Regexp.new(
'<div class="contextual heading-2" title="Edit this section" id="section-4">' \
'<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\\?section=4">' \
'<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-.*\\.svg#icon--edit"></use></svg>' \
'<span class="icon-label">Edit this section</span>' \
'</a></div>' \
'<a name="Section-C"></a>' \
'<h2 >Section C<a href="#Section-C" class="wiki-anchor">&para;</a></h2>'
),
result
)
end
end
def test_default_formatter
with_settings :text_formatting => 'unknown' do
text = 'a *link*: http://www.example.net/'
(3-3/3)