Add header_hashtag feature option: headers display a link icon when moused over so you can jump to sections
Move anchor processing into markup.rb Use dashes for spaces in the anchor hashtag
This commit is contained in:
@@ -73,7 +73,7 @@ a.absent {
|
||||
.markdown-body h4:hover a.anchor,
|
||||
.markdown-body h5:hover a.anchor,
|
||||
.markdown-body h6:hover a.anchor {
|
||||
background: url('/images/para.png') no-repeat 10px center;
|
||||
background: url('/images/para.png') no-repeat center center;
|
||||
text-decoration: none;
|
||||
}
|
||||
.markdown-body h1 tt,
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
<div id="wiki-content">
|
||||
<div class="wrap{{#has_footer}} has-footer{{/has_footer}}{{#has_sidebar}} has-rightbar{{/has_sidebar}}{{#has_toc}} has-toc{{/has_toc}}">
|
||||
<div class="{{#has_header}}has-header{{/has_header}}{{#has_footer}} has-footer{{/has_footer}}{{#has_sidebar}} has-rightbar{{/has_sidebar}}{{#has_toc}} has-toc{{/has_toc}}">
|
||||
{{#has_toc}}
|
||||
<div id="wiki-toc-main" class="gollum-{{sidebar_format}}-content">
|
||||
<h2>Table of contents</h2>
|
||||
|
||||
+10
-1
@@ -53,9 +53,18 @@ module Gollum
|
||||
end
|
||||
data = process_tags(data)
|
||||
data = process_code(data, encoding)
|
||||
if sanitize || block_given?
|
||||
if sanitize || block_given? || @wiki.header_anchors || @wiki.universal_toc
|
||||
doc = Nokogiri::HTML::DocumentFragment.parse(data)
|
||||
doc = sanitize.clean_node!(doc) if sanitize
|
||||
|
||||
doc.css('h1,h2,h3,h4,h5,h6').each do |h|
|
||||
link = CGI::escape(h.content.gsub(' ','-'))
|
||||
anchor = Nokogiri::XML::Node.new('a', doc)
|
||||
anchor['class'] = 'anchor'
|
||||
anchor['id'] = link
|
||||
anchor['href'] = '#' + link
|
||||
h.child.before(anchor)
|
||||
end if @wiki.header_anchors || @wiki.universal_toc
|
||||
yield doc if block_given?
|
||||
data = doc.to_html
|
||||
end
|
||||
|
||||
@@ -180,7 +180,6 @@ module Gollum
|
||||
formatted_data if @doc == nil
|
||||
toc = Toc.new(@doc)
|
||||
if (toc_content = toc.generate)
|
||||
toc.insert_anchors
|
||||
toc.generate.to_xhtml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XHTML)
|
||||
end
|
||||
end
|
||||
|
||||
+1
-16
@@ -35,28 +35,13 @@ module Gollum
|
||||
flatten_to_lvl(lvl, 0)
|
||||
end
|
||||
|
||||
# Escape title string for use in ID attribute
|
||||
#
|
||||
# title - Title string
|
||||
#
|
||||
# Returns string
|
||||
def insert_anchors
|
||||
find_headings.each do |h|
|
||||
rep_h = Nokogiri::XML::Node.new('a', @doc)
|
||||
rep_h['class'] = 'wiki-toc-anchor'
|
||||
rep_h['id'] = anchor_id(h.content)
|
||||
rep_h.add_child(h.clone)
|
||||
h.replace(rep_h)
|
||||
end
|
||||
end
|
||||
|
||||
# Escape title string for use in ID attribute
|
||||
#
|
||||
# title - Title string
|
||||
#
|
||||
# Returns string
|
||||
def anchor_id (title)
|
||||
CGI::escape(title)
|
||||
CGI::escape(title.gsub(' ','-'))
|
||||
end
|
||||
|
||||
# Convert heading into list element
|
||||
|
||||
@@ -134,6 +134,7 @@ module Gollum
|
||||
# site.
|
||||
# options - Optional Hash:
|
||||
# :universal_toc - Display table of contents on all pages. Default: false
|
||||
# :header_hashtags - Show links to headers. Default: true
|
||||
# :base_path - String base path for all Wiki links.
|
||||
# Default: "/"
|
||||
# :page_class - The page Class. Default: Gollum::Page
|
||||
@@ -166,6 +167,7 @@ module Gollum
|
||||
@history_sanitization = options[:history_sanitization] ||
|
||||
self.class.history_sanitization
|
||||
@universal_toc = options[:universal_toc] || false
|
||||
@header_hashtags = options[:header_hashtags] || true
|
||||
end
|
||||
|
||||
# Public: check whether the wiki's git repo exists on the filesystem.
|
||||
@@ -532,6 +534,9 @@ module Gollum
|
||||
# Toggles display of universal table of contents
|
||||
attr_reader :universal_toc
|
||||
|
||||
# Create hashtag link for headers to jump to sections
|
||||
attr_reader :header_hashtags
|
||||
|
||||
# Normalize the data.
|
||||
#
|
||||
# data - The String data to be normalized.
|
||||
|
||||
Reference in New Issue
Block a user