Index: hiki/plugin.rb
===================================================================
RCS file: /cvsroot/hiki/hiki/hiki/plugin.rb,v
retrieving revision 1.5
diff -u -r1.5 plugin.rb
--- hiki/plugin.rb 26 Jul 2004 07:53:43 -0000 1.5
+++ hiki/plugin.rb 4 Nov 2004 17:45:25 -0000
@@ -8,7 +8,7 @@
module Hiki
class Plugin
- attr_reader :toc_f, :plugin_command
+ attr_reader :toc_f, :toc_re, :plugin_command
attr_accessor :text, :title
def initialize( options, conf )
@@ -33,6 +33,7 @@
end
@toc_f = false
+@toc_re = nil
@plugin_command = []
@plugin_menu = []
@text = ''
Index: plugin/00default.rb
===================================================================
RCS file: /cvsroot/hiki/hiki/plugin/00default.rb,v
retrieving revision 1.12
diff -u -r1.12 00default.rb
--- plugin/00default.rb 28 Sep 2004 13:47:28 -0000 1.12
+++ plugin/00default.rb 4 Nov 2004 17:45:25 -0000
@@ -43,9 +43,15 @@
((pg_title && pg_title.size > 0) ? pg_title : page).escapeHTML
end
+#===== toc_pat
+def toc_pat(pat=nil)
+ @toc_re = Regexp.compile(pat) if pat
+end
+
#===== toc
-def toc
+def toc(pat=nil)
@toc_f = true
+ toc_pat(pat)
end
#===== recent
Index: style/default/html_formatter.rb
===================================================================
RCS file: /cvsroot/hiki/hiki/style/default/html_formatter.rb,v
retrieving revision 1.9
diff -u -r1.9 html_formatter.rb
--- style/default/html_formatter.rb 14 Sep 2004 02:21:10 -0000 1.9
+++ style/default/html_formatter.rb 4 Nov 2004 17:45:25 -0000
@@ -135,31 +135,50 @@
toc_title << t[:s] if toc_level > 0
when :wikiname, :bracketname
disp = t[:s]
+anchor_pos = t[:href].index('#')
+if anchor_pos
+ t[:anchor] = t[:href][anchor_pos+1..-1]
+ t[:href] =
+ if anchor_pos == 0
+ then @conf.options['page']
+ else t[:href][0...anchor_pos]
+ end
+end
t[:href] = @aliaswiki.aliaswiki_names.index(t[:href]) || t[:href]
if t[:e] == :bracketname
orig = @db.select {|p| p[:title] == t[:href]}
t[:href] = orig[0] if orig[0]
end
+page = t[:href].escape
+if t[:anchor]
+ page << '#' << t[:anchor].escape
+end
if !@conf.use_wikiname and t[:e] == :wikiname
html << disp.escapeHTML
elsif @db.exist?( t[:href] )
- html << @plugin.hiki_anchor(t[:href].escape, disp.escapeHTML)
+ html << @plugin.hiki_anchor(page, disp.escapeHTML)
@references << t[:href]
else
missing_anchor_title = msg_missing_anchor_title % [ disp.escapeHTML ]
- outer_alias = @interwiki.outer_alias(t[:href]) || "#{disp.escapeHTML}?"
+ outer_alias = @interwiki.outer_alias(t[:href]) || "#{disp.escapeHTML}?"
html << outer_alias
end
- toc_title << t[:href] if toc_level > 0
+ toc_title << page if toc_level > 0
when :interwiki
html << @interwiki.interwiki(t[:href], t[:p], t[:s])
when :empty
html << "\n"
when :heading1_open, :heading2_open, :heading3_open, :heading4_open, :heading5_open
toc_level = t[:lv]
- html << %Q!#{MAP[t[:e]]} !
+ html << %Q!#{MAP[t[:e]]}!
when :heading1_close, :heading2_close, :heading3_close, :heading4_close, :heading5_close
- add_toc( toc_level, toc_title )
+anchor_name =
+ if @plugin.toc_re
+ then @plugin.toc_re.match(toc_title).to_a[1]
+ else "#{@suffix}#{@toc_cnt}"
+ end
+html.sub!( //, %Q! ! )
+ add_toc( toc_level, toc_title, anchor_name )
toc_level = 0
toc_title = ''
html << "#{MAP[t[:e]]}\n"
@@ -215,12 +234,12 @@
s << ( "#{MAP[:unordered_list_close]}\n" * ( lv - h['level'] ) )
lv = h['level']
end
- s << %Q!#{MAP[:listitem_open]}#{h['title'].escapeHTML}#{MAP[:listitem_close]}\n!
+ s << %Q!#{MAP[:listitem_open]}#{h['title'].escapeHTML}#{MAP[:listitem_close]}\n!
end
s << ("#{MAP[:unordered_list_close]}\n" * lv)
s << ""
end
-
+
def apply_tdiary_theme(orig_html)
section = ''
title = ''
@@ -241,8 +260,8 @@
end
private
- def add_toc( level, title )
- @toc << {"level" => level, "title" => title, "index" => @toc_cnt}
+ def add_toc( level, title, anchor_name )
+ @toc << {"level" => level, "title" => title, "anchor" => anchor_name, "index" => @toc_cnt}
@toc_cnt = @toc_cnt + 1
end