diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8d4f90c..e1048ea 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -449,12 +449,19 @@ module ApplicationHelper only_path = options.delete(:only_path) == false ? false : true text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text, :object => obj, :attribute => attr) { |macro, args| exec_macro(macro, obj, args) } - - parse_non_pre_blocks(text) do |text| + + @parsed_headings = [] + text = parse_non_pre_blocks(text) do |text| [:parse_inline_attachments, :parse_wiki_links, :parse_redmine_links, :parse_headings].each do |method_name| send method_name, text, project, obj, attr, only_path, options end end + + if @parsed_headings.any? + replace_toc(text, @parsed_headings) + end + + text end def parse_non_pre_blocks(text) @@ -674,21 +681,26 @@ module ApplicationHelper end end - TOC_RE = /
\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
HEADING_RE = / \{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
+
+ # Renders the TOC with given headings
+ def replace_toc(text, headings)
text.gsub!(TOC_RE) do
if headings.empty?
''
diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb
index 4610bee..5f5eefa 100644
--- a/test/unit/helpers/application_helper_test.rb
+++ b/test/unit/helpers/application_helper_test.rb
@@ -428,7 +428,11 @@ Nullam commodo metus accumsan nulla. Curabitur lobortis dui id dolor.
h2. Subtitle with [[Wiki|another Wiki]] link
h2. Subtitle with %{color:red}red text%
-
+
+
+some code
+
+
h3. Subtitle with *some* _modifiers_
h1. Another title
@@ -464,7 +468,7 @@ RAW
''
@project = Project.find(1)
- assert textilizable(raw).gsub("\n", "").include?(expected)
+ assert textilizable(raw).gsub("\n", "").include?(expected), textilizable(raw)
end
def test_table_of_content_should_contain_included_page_headings