##// END OF EJS Templates
Fixed: partial toc when text contains pre tags (#7172)....
Jean-Philippe Lang -
r4464:af7006dff6f8
parent child
Show More
@@ -449,12 +449,19 module ApplicationHelper
449 449 only_path = options.delete(:only_path) == false ? false : true
450 450
451 451 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) }
452
453 parse_non_pre_blocks(text) do |text|
452
453 @parsed_headings = []
454 text = parse_non_pre_blocks(text) do |text|
454 455 [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_headings].each do |method_name|
455 456 send method_name, text, project, obj, attr, only_path, options
456 457 end
457 458 end
459
460 if @parsed_headings.any?
461 replace_toc(text, @parsed_headings)
462 end
463
464 text
458 465 end
459 466
460 467 def parse_non_pre_blocks(text)
@@ -674,21 +681,26 module ApplicationHelper
674 681 end
675 682 end
676 683
677 TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
678 684 HEADING_RE = /<h(1|2|3|4)( [^>]+)?>(.+?)<\/h(1|2|3|4)>/i unless const_defined?(:HEADING_RE)
679 685
680 686 # Headings and TOC
681 # Adds ids and links to headings and renders the TOC if needed unless options[:headings] is set to false
687 # Adds ids and links to headings unless options[:headings] is set to false
682 688 def parse_headings(text, project, obj, attr, only_path, options)
683 headings = []
689 return if options[:headings] == false
690
684 691 text.gsub!(HEADING_RE) do
685 692 level, attrs, content = $1.to_i, $2, $3
686 693 item = strip_tags(content).strip
687 694 anchor = item.gsub(%r{[^\w\s\-]}, '').gsub(%r{\s+(\-+\s*)?}, '-')
688 headings << [level, anchor, item]
695 @parsed_headings << [level, anchor, item]
689 696 "<h#{level} #{attrs} id=\"#{anchor}\">#{content}<a href=\"##{anchor}\" class=\"wiki-anchor\">&para;</a></h#{level}>"
690 end unless options[:headings] == false
691
697 end
698 end
699
700 TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
701
702 # Renders the TOC with given headings
703 def replace_toc(text, headings)
692 704 text.gsub!(TOC_RE) do
693 705 if headings.empty?
694 706 ''
@@ -428,7 +428,11 Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
428 428 h2. Subtitle with [[Wiki|another Wiki]] link
429 429
430 430 h2. Subtitle with %{color:red}red text%
431
431
432 <pre>
433 some code
434 </pre>
435
432 436 h3. Subtitle with *some* _modifiers_
433 437
434 438 h1. Another title
@@ -464,7 +468,7 RAW
464 468 '</ul>'
465 469
466 470 @project = Project.find(1)
467 assert textilizable(raw).gsub("\n", "").include?(expected)
471 assert textilizable(raw).gsub("\n", "").include?(expected), textilizable(raw)
468 472 end
469 473
470 474 def test_table_of_content_should_contain_included_page_headings
General Comments 0
You need to be logged in to leave comments. Login now