Added table of contents to wiki page.
This commit is contained in:
parent
d371839eba
commit
2660d86b89
6 changed files with 35 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
|||
module PagesHelper
|
||||
|
||||
def wikified_body(body)
|
||||
r = RedCloth.new(body)
|
||||
r = RedCloth.new(generate_anchors(body))
|
||||
r.gsub!(/\[\[(.*?)(\|(.*?))?\]\]/) { wiki_link($1, $3) }
|
||||
sanitize r.to_html
|
||||
r.to_html
|
||||
|
@ -15,4 +15,25 @@ module PagesHelper
|
|||
link_to((link_text || wiki_words), wiki_page_url(permalink), :class => "new_wiki_link")
|
||||
end
|
||||
end
|
||||
|
||||
def generate_toc(body)
|
||||
toc = ""
|
||||
body.gsub(/^\s*h([1-6])\.\s+(.*)/) do
|
||||
number = $1
|
||||
name = $2
|
||||
header = name.downcase.gsub(' ', '-')
|
||||
toc << '#' * number.to_i + ' "' + name + '":#' + header + "\n"
|
||||
end
|
||||
RedCloth.new(toc).to_html
|
||||
end
|
||||
|
||||
def generate_anchors(body)
|
||||
body.gsub(/^\s*h([1-6])\.\s+(.*)/) do
|
||||
number = $1
|
||||
name = $2
|
||||
header = name.downcase.gsub(' ', '-')
|
||||
"\nh#{number}. #{name}<a name ='#{header}'> </a>"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
#toc
|
||||
%h2 Inhaltsverzeichnis
|
||||
= generate_toc @page.body
|
||||
= wikified_body @page.body
|
|
@ -7,7 +7,7 @@
|
|||
%ul
|
||||
- for version in @page.versions.reverse
|
||||
%li
|
||||
= link_to format_datetime(version.updated_at), version_page_path(@page, :version => version.version)
|
||||
= link_to format_time(version.updated_at), version_page_path(@page, :version => version.version)
|
||||
= "(#{User.find(version.updated_by).nick})"
|
||||
|
||||
|
||||
|
|
|
@ -444,3 +444,6 @@ a.new_wiki_link {
|
|||
#preview {
|
||||
border: 1px dotted grey;
|
||||
padding: 0 1em; }
|
||||
|
||||
#toc {
|
||||
float: right; }
|
||||
|
|
|
@ -445,6 +445,9 @@ a.new_wiki_link {
|
|||
border: 1px dotted grey;
|
||||
padding: 0 1em; }
|
||||
|
||||
#toc {
|
||||
float: right; }
|
||||
|
||||
#logininfo, #header, #footer {
|
||||
display: none; }
|
||||
|
||||
|
|
|
@ -491,3 +491,5 @@ a.new_wiki_link
|
|||
#preview
|
||||
border: 1px dotted grey
|
||||
padding: 0 1em
|
||||
#toc
|
||||
float: right
|
Loading…
Reference in a new issue