Project

General

Profile

Defect #35036 ยป 0001-markdown_formatter-extract_sections-fix.patch

extract_sections fix for dash thematic breaks + unit tests - Martin Cizek, 2021-04-05 16:05

View differences:

lib/redmine/wiki_formatting/markdown/formatter.rb
89 89
          i = 0
90 90
          l = 1
91 91
          inside_pre = false
92
          @text.split(/(^(?:.+\r?\n\r?(?:\=+|\-+)|#+.+|(?:~~~|```).*)\s*$)/).each do |part|
92
          @text.split(/(^(?:\S+\r?\n\r?(?:\=+|\-+)|#+.+|(?:~~~|```).*)\s*$)/).each do |part|
93 93
            level = nil
94 94
            if part =~ /\A(~{3,}|`{3,})(\s*\S+)?\s*$/
95 95
              if !inside_pre
test/unit/lib/redmine/wiki_formatting/markdown_formatter_test.rb
180 180
    )
181 181
  end
182 182

  
183
  STR_SETEXT_LIKE = [
184
    # 0
185
    <<~STR.chomp,
186
      # Title
187
    STR
188
    # 1
189
    <<~STR.chomp,
190
      ## Heading 2
191

  
192
      Thematic breaks - not be confused with setext headings.
193

  
194
      ---
195

  
196
      Preceding CRLF is the default for web-submitted data.
197
      \r
198
      ---\r
199
      \r
200

  
201
      A space-only line does not mean much.
202
      \s
203
      ---
204

  
205
      End of thematic breaks.
206
    STR
207
    # 2
208
    <<~STR.chomp,
209
      ## Heading 2
210
      Nulla nunc nisi, egestas in ornare vel, posuere ac libero.
211
    STR
212
  ]
213

  
214
  STR_RARE_SETEXT_LIKE = [
215
    # 0
216
    <<~STR.chomp,
217
      # Title
218
    STR
219
    # 1
220
    <<~STR.chomp,
221
      ## Heading 2
222

  
223
      - item
224
      one
225
      -
226
      not a heading
227
    STR
228
    # 2
229
    <<~STR.chomp,
230
      ## Heading 2
231
      Nulla nunc nisi, egestas in ornare vel, posuere ac libero.
232
    STR
233
  ]
234

  
235
  def test_get_section_should_ignore_setext_like_text
236
    text = STR_SETEXT_LIKE.join("\n\n")
237
    assert_section_with_hash STR_SETEXT_LIKE[1], text, 2
238
    assert_section_with_hash STR_SETEXT_LIKE[2], text, 3
239
  end
240

  
241
  def test_get_section_should_ignore_rare_setext_like_text
242
    begin
243
      text = STR_RARE_SETEXT_LIKE.join("\n\n")
244
      assert_section_with_hash STR_RARE_SETEXT_LIKE[1], text, 2
245
      assert_section_with_hash STR_RARE_SETEXT_LIKE[2], text, 3
246
    rescue Minitest::Assertion => e
247
      skip "Section extraction is currently limited, see #35037. Known error: #{e.message}"
248
    end
249
    refute "This test should be adjusted when fixing the known error."
250
  end
251

  
183 252
  def test_should_support_underlined_text
184 253
    text = 'This _text_ should be underlined'
185 254
    assert_equal '<p>This <u>text</u> should be underlined</p>', @formatter.new(text).to_html.strip
    (1-1/1)