Merged r12989 and r12997 (#16236).
git-svn-id: http://svn.redmine.org/redmine/branches/2.5-stable@13020 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
58786e8d80
commit
c5b52ec29f
@ -978,19 +978,20 @@ module ApplicationHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
TOC_RE = /<p>\{\{([<>]?)toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
|
TOC_RE = /<p>\{\{((<|<)|(>|>))?toc\}\}<\/p>/i unless const_defined?(:TOC_RE)
|
||||||
|
|
||||||
# Renders the TOC with given headings
|
# Renders the TOC with given headings
|
||||||
def replace_toc(text, headings)
|
def replace_toc(text, headings)
|
||||||
text.gsub!(TOC_RE) do
|
text.gsub!(TOC_RE) do
|
||||||
|
left_align, right_align = $2, $3
|
||||||
# Keep only the 4 first levels
|
# Keep only the 4 first levels
|
||||||
headings = headings.select{|level, anchor, item| level <= 4}
|
headings = headings.select{|level, anchor, item| level <= 4}
|
||||||
if headings.empty?
|
if headings.empty?
|
||||||
''
|
''
|
||||||
else
|
else
|
||||||
div_class = 'toc'
|
div_class = 'toc'
|
||||||
div_class << ' right' if $1 == '>'
|
div_class << ' right' if right_align
|
||||||
div_class << ' left' if $1 == '<'
|
div_class << ' left' if left_align
|
||||||
out = "<ul class=\"#{div_class}\"><li>"
|
out = "<ul class=\"#{div_class}\"><li>"
|
||||||
root = headings.map(&:first).min
|
root = headings.map(&:first).min
|
||||||
current = root
|
current = root
|
||||||
|
@ -1167,6 +1167,24 @@ RAW
|
|||||||
assert textilizable(raw).gsub("\n", "").include?(expected)
|
assert textilizable(raw).gsub("\n", "").include?(expected)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_toc_with_textile_formatting_should_be_parsed
|
||||||
|
with_settings :text_formatting => 'textile' do
|
||||||
|
assert_select_in textilizable("{{toc}}\n\nh1. Heading"), 'ul.toc li', :text => 'Heading'
|
||||||
|
assert_select_in textilizable("{{<toc}}\n\nh1. Heading"), 'ul.toc.left li', :text => 'Heading'
|
||||||
|
assert_select_in textilizable("{{>toc}}\n\nh1. Heading"), 'ul.toc.right li', :text => 'Heading'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if Object.const_defined?(:Redcarpet)
|
||||||
|
def test_toc_with_markdown_formatting_should_be_parsed
|
||||||
|
with_settings :text_formatting => 'markdown' do
|
||||||
|
assert_select_in textilizable("{{toc}}\n\n# Heading"), 'ul.toc li', :text => 'Heading'
|
||||||
|
assert_select_in textilizable("{{<toc}}\n\n# Heading"), 'ul.toc.left li', :text => 'Heading'
|
||||||
|
assert_select_in textilizable("{{>toc}}\n\n# Heading"), 'ul.toc.right li', :text => 'Heading'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_section_edit_links
|
def test_section_edit_links
|
||||||
raw = <<-RAW
|
raw = <<-RAW
|
||||||
h1. Title
|
h1. Title
|
||||||
|
Loading…
x
Reference in New Issue
Block a user