1 ###############################################################################
3 # book¥×¥é¥°¥¤¥ó¤ËÂбþ¤·¤¿¥¢¥¦¥È¥é¥¤¥ó¥Ñ¡¼¥µ
5 ###############################################################################
6 package plugin::book::TocParser;
11 @ISA = qw(Wiki::HTMLParser);
13 #==============================================================================
15 #==============================================================================
18 my $self = Wiki::HTMLParser->new(shift);
23 $self->{'display_level'} = $level;
25 $self->{'display_level'} = 3;
28 $self->{'outline_html'} = "";
29 $self->{'outline_level'} = 0;
30 $self->{'outline_cnt'} = 0;
31 $self->{'outline_fix'} = 0;
32 $self->{'pagename'} = $page;
33 $self->{'section_cnt'} = 0;
34 return bless $self,$class;
37 #==============================================================================
38 # ¥Ø¥Ã¥É¥é¥¤¥ó¤Î¤ßÃê½Ð
39 #==============================================================================
45 $level = $level + $self->{'outline_fix'};
47 if($level > $self->{'display_level'}){
48 $self->{outline_cnt}++;
52 my $text = &Util::delete_tag(join("",@$obj));
54 if($level > $self->{outline_level}){
55 while($level!=$self->{outline_level}){
56 if($self->{'outline_close_'.($self->{outline_level})} == 1){
\r
57 $self->{outline_html} .= "</li>\n";
\r
58 $self->{'outline_close_'.($self->{outline_level})} = 0;
\r
60 $self->{outline_html} .= "<ul class=\"outline\">\n";
61 $self->{outline_level}++;
63 } elsif($level <= $self->{outline_level}){
64 while($level-1 != $self->{outline_level}){
65 if($self->{'outline_close_'.($self->{outline_level})} == 1){
66 $self->{outline_html} .= "</li>\n";
67 $self->{'outline_close_'.($self->{outline_level})} = 0;
69 if($level == $self->{outline_level}){
72 $self->{outline_html} .= "</ul>\n";
73 $self->{outline_level}--;
76 $self->{outline_html} .= "</li>\n";
79 $self->{'outline_close_'.$level} = 1;
80 if($self->{'outline_fix'} == 1 && $level == 1){
81 $self->{outline_html} .= "<li>$text";
83 $self->{outline_html} .= "<li><a href=\"?page=".Util::url_encode($self->{pagename})."#p".$self->{outline_cnt}."\">$text</a>";
84 $self->{outline_cnt}++;
88 #==============================================================================
89 # ¥¢¥¦¥È¥é¥¤¥óɽ¼¨ÍÑHTML¤Î¼èÆÀ
90 #==============================================================================
94 $self->parse($source);
96 while($self->{outline_level} != 0){
97 if($self->{'outline_close_'.($self->{outline_level})} == 1){
98 $self->{outline_html} .= "</li>\n";
100 $self->{outline_html} .= "</ul>\n";
101 $self->{outline_level}--;
104 return $self->{outline_html};
107 #==============================================================================
108 # ¥×¥é¥°¥¤¥ó¤Î²òÀϤò¹Ô¤¦¤È̵¸Â¥ë¡¼¥×¤·¤Æ¤·¤Þ¤¦¤¿¤á
109 #==============================================================================
114 if($plugin->{'command'} eq 'title1'){
116 $self->{'title2'} = 0;
117 $self->{'title3'} = 0;
118 return $self->{'chapter'}.'-'.$self->{'title1'}.'. ';
120 } elsif($plugin->{'command'} eq 'title2'){
122 $self->{'title3'} = 0;
123 return $self->{'chapter'}.'-'.$self->{'title1'}.'-'.$self->{'title2'}.'. ';
125 } elsif($plugin->{'command'} eq 'title3'){
127 return $self->{'chapter'}.'-'.$self->{'title1'}.'-'.$self->{'title2'}.'-'.$self->{'title3'}.'. ';
133 #==============================================================================
134 # ¥×¥é¥°¥¤¥ó¤Î²òÀϤò¹Ô¤¦¤È̵¸Â¥ë¡¼¥×¤·¤Æ¤·¤Þ¤¦¤¿¤á
135 #==============================================================================
140 if($plugin->{'command'} eq 'chapter'){
141 $self->{'chapter'} = $plugin->{'args'}->[0];
144 if($plugin->{'command'} eq 'section'){
145 if($self->{'outline_fix'} == 0){
146 $self->{'outline_fix'} = 1;
147 $self->{'display_level'}++;
149 $self->{'section_cnt'}++;
150 $self->l_headline(0, [$plugin->{'args'}->[0]]);
154 # outline°Ê³°¤Î¾ì¹ç¤Î¤ß½èÍý¤ò¹Ô¤¦
155 if($plugin->{command} ne "outline"){
156 my $info = $self->{wiki}->get_plugin_info($plugin->{command});
157 if($info->{FORMAT} eq "WIKI"){
158 return $self->SUPER::l_plugin($plugin);