##// END OF EJS Templates
Do not parse redmine links inside pre/code tags (#1288)....
Jean-Philippe Lang -
r3475:7203196212ae
parent child
Show More
@@ -409,12 +409,37 module ApplicationHelper
409 only_path = options.delete(:only_path) == false ? false : true
409 only_path = options.delete(:only_path) == false ? false : true
410
410
411 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
411 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
412
412
413 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
413 parse_non_pre_blocks(text) do |text|
414 send method_name, text, project, obj, attr, only_path, options
414 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links].each do |method_name|
415 send method_name, text, project, obj, attr, only_path, options
416 end
415 end
417 end
416
418 end
417 text
419
420 def parse_non_pre_blocks(text)
421 s = StringScanner.new(text)
422 tags = []
423 parsed = ''
424 while !s.eos?
425 s.scan(/(.*?)(<(\/)?(pre|code)(.*?)>|\z)/im)
426 text, full_tag, closing, tag = s[1], s[2], s[3], s[4]
427 if tags.empty?
428 yield text
429 end
430 parsed << text
431 if tag
432 if closing
433 if tags.last == tag.downcase
434 tags.pop
435 end
436 else
437 tags << tag.downcase
438 end
439 parsed << full_tag
440 end
441 end
442 parsed
418 end
443 end
419
444
420 def parse_inline_attachments(text, project, obj, attr, only_path, options)
445 def parse_inline_attachments(text, project, obj, attr, only_path, options)
@@ -297,6 +297,33 EXPECTED
297 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
297 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
298 end
298 end
299
299
300 def test_pre_content_should_not_parse_wiki_and_redmine_links
301 raw = <<-RAW
302 [[CookBook documentation]]
303
304 #1
305
306 <pre>
307 [[CookBook documentation]]
308
309 #1
310 </pre>
311 RAW
312
313 expected = <<-EXPECTED
314 <p><a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a></p>
315 <p><a href="/issues/1" class="issue status-1 priority-1" title="Can't print recipes (New)">#1</a></p>
316 <pre>
317 [[CookBook documentation]]
318
319 #1
320 </pre>
321 EXPECTED
322
323 @project = Project.find(1)
324 assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
325 end
326
300 def test_syntax_highlight
327 def test_syntax_highlight
301 raw = <<-RAW
328 raw = <<-RAW
302 <pre><code class="ruby">
329 <pre><code class="ruby">
General Comments 0
You need to be logged in to leave comments. Login now