diff --git i/test/unit/lib/redmine/wiki_formatting/macros_test.rb w/test/unit/lib/redmine/wiki_formatting/macros_test.rb index 8c3011575..41a7e6857 100644 --- i/test/unit/lib/redmine/wiki_formatting/macros_test.rb +++ w/test/unit/lib/redmine/wiki_formatting/macros_test.rb @@ -314,6 +314,97 @@ class Redmine::WikiFormatting::MacrosTest < Redmine::HelperTest end end + BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE = + %r{]*)?>(?:(?!

).)*<(?:div|h[1-6]|hr|ol|pre|table|ul)[\s/>]}m + + def test_macro_returning_block_level_content_should_not_be_wrapped_in_paragraph + text = <<~RAW + {{collapse(Show example, Hide example) + h2. Heading + + Some text + }} + RAW + %w[textile common_mark].each do |format| + with_settings :text_formatting => format do + assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable(text) + end + end + end + + def test_include_macro_should_not_be_wrapped_in_paragraph + @project = Project.find(1) + %w[textile common_mark].each do |format| + with_settings :text_formatting => format do + assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable('{{include(Another page)}}') + end + end + end + + # Example 1 of #43730: text between collapses in the same paragraph + def test_macro_multiple_collapse_with_text_between_should_not_generate_block_inside_p + text = <<~RAW + 1 {{collapse(1) + content 1 + }} + 2 {{collapse(2) + content 2 + }} + 3 {{collapse(3) + content 3 + }} + RAW + with_settings :text_formatting => 'textile' do + assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable(text) + end + end + + # Example 2 of #43730: adjacent collapses with no text between + def test_macro_multiple_collapse_adjacent_should_not_generate_block_inside_p + text = <<~RAW + {{collapse(1) + content 1 + }} + {{collapse(2) + content 2 + }} + RAW + with_settings :text_formatting => 'textile' do + assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable(text) + end + end + + # Example 3 of #43730: multiple groups of collapses separated by a blank line + def test_macro_multiple_collapse_groups_should_not_generate_block_inside_p + text = <<~RAW + 1 {{collapse(1) + content 1 + }} + 2 {{collapse(2) + content 2 + }} + + 3 {{collapse(3) + content 3 + }} + RAW + with_settings :text_formatting => 'textile' do + assert_no_match BLOCK_LEVEL_CONTENT_IN_PARAGRAPH_RE, textilizable(text) + end + end + + def test_macro_returning_inline_content_should_keep_its_paragraph + with_settings :text_formatting => 'textile' do + assert_match %r{

Some text: 'textile' do + assert_equal '

Some text

', textilizable('Some text').strip + end + end + def test_macro_child_pages expected = "