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
971 971
    @heading_anchors = {}
972 972
    @current_section = 0 if options[:edit_section_links]
973
    parse_sections(text, project, obj, attr, only_path, options)
974 973
    text = parse_non_pre_blocks(text, obj, macros, options) do |txt|
975 974
      [:parse_wiki_links, :parse_redmine_links].each do |method_name|
976 975
        send method_name, txt, project, obj, attr, only_path, options
977 976
      end
978 977
    end
978
    parse_sections(text, project, obj, attr, only_path, options)
979 979
    parse_headings(text, project, obj, attr, only_path, options)
980 980
    if @parsed_headings.any?
test/helpers/application_helper_test.rb
1624 1624
    end
1625 1625
  end
1626
  def test_section_edit_links_with_collapse_macro
1627
    raw = <<~RAW
1628
      # Wiki
1629
      ## Section A
1630

  
1631
      collapsed section
1632
      {{collapse(View details...)
1633
      ## Section B
1634
      }}
1635

  
1636
      ## Section C
1637
    RAW
1638
    @project = Project.find(1)
1639
    set_language_if_valid 'en'
1640
    with_settings :text_formatting => 'common_mark' do
1641
      result =
1642
        textilizable(
1643
          raw,
1644
          :edit_section_links =>
1645
            {:controller => 'wiki', :action => 'edit',
1646
            :project_id => '1', :id => 'Test'}
1647
        ).delete("\n")
1648

  
1649
      # Section B inside collapse macro should have section=3 edit link
1650
      assert_match(
1651
        Regexp.new(
1652
          '<div class="contextual heading-2" title="Edit this section" id="section-3">' \
1653
          '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\\?section=3">' \
1654
          '<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-.*\\.svg#icon--edit"></use></svg>' \
1655
          '<span class="icon-label">Edit this section</span>' \
1656
          '</a></div>' \
1657
          '<a name="Section-B"></a>' \
1658
          '<h2 >Section B<a href="#Section-B" class="wiki-anchor">&para;</a></h2>'
1659
        ),
1660
        result
1661
      )
1662

  
1663
      # Section C after collapse macro should have section=4 edit link
1664
      assert_match(
1665
        Regexp.new(
1666
          '<div class="contextual heading-2" title="Edit this section" id="section-4">' \
1667
          '<a class="icon-only icon-edit" href="/projects/1/wiki/Test/edit\\?section=4">' \
1668
          '<svg class="s18 icon-svg" aria-hidden="true"><use href="/assets/icons-.*\\.svg#icon--edit"></use></svg>' \
1669
          '<span class="icon-label">Edit this section</span>' \
1670
          '</a></div>' \
1671
          '<a name="Section-C"></a>' \
1672
          '<h2 >Section C<a href="#Section-C" class="wiki-anchor">&para;</a></h2>'
1673
        ),
1674
        result
1675
      )
1676
    end
1677
  end
1678

  
1679

  
1626 1680
  def test_default_formatter
1627 1681
    with_settings :text_formatting => 'unknown' do
1628 1682
      text = 'a *link*: http://www.example.net/'
(3-3/3)