diff --git a/lib/redmine/wiki_formatting/markdown/formatter.rb b/lib/redmine/wiki_formatting/markdown/formatter.rb index 9d1637125..418ab8b14 100644 --- a/lib/redmine/wiki_formatting/markdown/formatter.rb +++ b/lib/redmine/wiki_formatting/markdown/formatter.rb @@ -89,7 +89,7 @@ module Redmine i = 0 l = 1 inside_pre = false - @text.split(/(^(?:.+\r?\n\r?(?:\=+|\-+)|#+.+|(?:~~~|```).*)\s*$)/).each do |part| + @text.split(/(^(?:\S+\r?\n\r?(?:\=+|\-+)|#+.+|(?:~~~|```).*)\s*$)/).each do |part| level = nil if part =~ /\A(~{3,}|`{3,})(\s*\S+)?\s*$/ if !inside_pre diff --git a/test/unit/lib/redmine/wiki_formatting/markdown_formatter_test.rb b/test/unit/lib/redmine/wiki_formatting/markdown_formatter_test.rb index 561e7aa02..e3bb6ee79 100644 --- a/test/unit/lib/redmine/wiki_formatting/markdown_formatter_test.rb +++ b/test/unit/lib/redmine/wiki_formatting/markdown_formatter_test.rb @@ -180,6 +180,75 @@ class Redmine::WikiFormatting::MarkdownFormatterTest < ActionView::TestCase ) end + STR_SETEXT_LIKE = [ + # 0 + <<~STR.chomp, + # Title + STR + # 1 + <<~STR.chomp, + ## Heading 2 + + Thematic breaks - not be confused with setext headings. + + --- + + Preceding CRLF is the default for web-submitted data. + \r + ---\r + \r + + A space-only line does not mean much. + \s + --- + + End of thematic breaks. + STR + # 2 + <<~STR.chomp, + ## Heading 2 + Nulla nunc nisi, egestas in ornare vel, posuere ac libero. + STR + ] + + STR_RARE_SETEXT_LIKE = [ + # 0 + <<~STR.chomp, + # Title + STR + # 1 + <<~STR.chomp, + ## Heading 2 + + - item + one + - + not a heading + STR + # 2 + <<~STR.chomp, + ## Heading 2 + Nulla nunc nisi, egestas in ornare vel, posuere ac libero. + STR + ] + + def test_get_section_should_ignore_setext_like_text + text = STR_SETEXT_LIKE.join("\n\n") + assert_section_with_hash STR_SETEXT_LIKE[1], text, 2 + assert_section_with_hash STR_SETEXT_LIKE[2], text, 3 + end + + def test_get_section_should_ignore_rare_setext_like_text + begin + text = STR_RARE_SETEXT_LIKE.join("\n\n") + assert_section_with_hash STR_RARE_SETEXT_LIKE[1], text, 2 + assert_section_with_hash STR_RARE_SETEXT_LIKE[2], text, 3 + rescue Minitest::Assertion => e + skip "Section extraction is currently limited, see #35037. Known error: #{e.message}" + end + refute "This test should be adjusted when fixing the known error." + end + def test_should_support_underlined_text text = 'This _text_ should be underlined' assert_equal '

This text should be underlined

', @formatter.new(text).to_html.strip