Defect #43730 » patch-issue-43730-fix-collapse-macro-invalid-html.diff
| app/helpers/application_helper.rb | ||
|---|---|---|
|
send method_name, txt, project, obj, attr, only_path, options
|
||
|
end
|
||
|
end
|
||
|
unwrap_paragraphs_containing_block_macros(text)
|
||
|
parse_headings(text, project, obj, attr, only_path, options)
|
||
|
if @parsed_headings.any?
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
# Fixes invalid HTML where block-level elements from macros (e.g. collapse)
|
||
|
# are nested inside <p> tags. Replaces the <p></p> with <div></div> so that
|
||
|
# consecutive paragraphs remain visually separated as block-level elements.
|
||
|
# Uses a pattern that treats <div class="collapsed-text">...</div> as atomic
|
||
|
# so that </p> inside the div's content does not end the outer match early.
|
||
|
def unwrap_paragraphs_containing_block_macros(text)
|
||
|
collapsed_div = /<div[^>]*class="[^"]*collapsed-text[^"]*"[^>]*>(?:(?!<\/div>).)*<\/div>/m
|
||
|
non_collapsed = /(?!<\/p>)(?!<div[^>]*class="[^"]*collapsed-text)./m
|
||
|
text.gsub!(
|
||
|
/<p>(#{non_collapsed}*(?:#{collapsed_div}#{non_collapsed}*)+)<\/p>/m,
|
||
|
'<div>\1</div>'
|
||
|
)
|
||
|
end
|
||
|
TOC_RE = /<p>\{\{((<|<)|(>|>))?toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
|
||
|
# Renders the TOC with given headings
|
||
| test/unit/lib/redmine/wiki_formatting/macros_test.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
COLLAPSE_INVALID_HTML_RE = /<p>(?:(?!<\/p>).)*<div[^>]*class="[^"]*collapsed-text/m
|
||
|
# Example 1: text between collapses in the same paragraph
|
||
|
def test_macro_multiple_collapse_with_text_between_should_not_generate_div_inside_p
|
||
|
text = <<~RAW
|
||
|
1 {{collapse(1)
|
||
|
content 1
|
||
|
}}
|
||
|
2 {{collapse(2)
|
||
|
content 2
|
||
|
}}
|
||
|
3 {{collapse(3)
|
||
|
content 3
|
||
|
}}
|
||
|
RAW
|
||
|
with_locale 'en' do
|
||
|
with_settings :text_formatting => 'textile' do
|
||
|
assert_no_match(COLLAPSE_INVALID_HTML_RE, textilizable(text))
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
# Example 2: adjacent collapses with no text between
|
||
|
def test_macro_multiple_collapse_adjacent_should_not_generate_div_inside_p
|
||
|
text = <<~RAW
|
||
|
{{collapse(1)
|
||
|
content 1
|
||
|
}}
|
||
|
{{collapse(2)
|
||
|
content 2
|
||
|
}}
|
||
|
{{collapse(3)
|
||
|
content 3
|
||
|
}}
|
||
|
RAW
|
||
|
with_locale 'en' do
|
||
|
with_settings :text_formatting => 'textile' do
|
||
|
assert_no_match(COLLAPSE_INVALID_HTML_RE, textilizable(text))
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
# Example 3: multiple groups of collapses separated by a blank line
|
||
|
def test_macro_multiple_collapse_groups_should_not_generate_div_inside_p
|
||
|
text = <<~RAW
|
||
|
1 {{collapse(1)
|
||
|
content 1
|
||
|
}}
|
||
|
2 {{collapse(2)
|
||
|
content 2
|
||
|
}}
|
||
|
3 {{collapse(3)
|
||
|
content 3
|
||
|
}}
|
||
|
4 {{collapse(4)
|
||
|
content 4
|
||
|
}}
|
||
|
RAW
|
||
|
with_locale 'en' do
|
||
|
with_settings :text_formatting => 'textile' do
|
||
|
assert_no_match(COLLAPSE_INVALID_HTML_RE, textilizable(text))
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def test_macro_child_pages
|
||
|
expected =
|
||
|
"<p><ul class=\"pages-hierarchy\">\n" \
|
||