c&d: html, ocn link back to self reinstated
[software/sisu] / lib / sisu / develop / html_minitoc.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** html minitoc
8
9 ** Author: Ralph Amissah
10 <ralph@amissah.com>
11 <ralph.amissah@gmail.com>
12
13 ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
15 All Rights Reserved.
16
17 ** License: GPL 3 or later:
18
19 SiSU, a framework for document structuring, publishing and search
20
21 Copyright (C) Ralph Amissah
22
23 This program is free software: you can redistribute it and/or modify it
24 under the terms of the GNU General Public License as published by the Free
25 Software Foundation, either version 3 of the License, or (at your option)
26 any later version.
27
28 This program is distributed in the hope that it will be useful, but WITHOUT
29 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
31 more details.
32
33 You should have received a copy of the GNU General Public License along with
34 this program. If not, see <http://www.gnu.org/licenses/>.
35
36 If you have Internet connection, the latest version of the GPL should be
37 available at these locations:
38 <http://www.fsf.org/licensing/licenses/gpl.html>
39 <http://www.gnu.org/licenses/gpl.html>
40
41 <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
42
43 ** SiSU uses:
44 * Standard SiSU markup syntax,
45 * Standard SiSU meta-markup syntax, and the
46 * Standard SiSU object citation numbering and system
47
48 ** Hompages:
49 <http://www.jus.uio.no/sisu>
50 <http://www.sisudoc.org>
51
52 ** Git
53 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
54 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/develop/html_minitoc.rb;hb=HEAD>
55
56 =end
57 module SiSU_HTML_MiniToc
58 require_relative 'html_tune' # html_tune.rb
59 include SiSU_HTML_Tune
60 class TocMini
61 @@seg_mini=nil
62 @@seg_url=''
63 @@firstseg=nil
64 def initialize(md,data)
65 @md,@data=md,data
66 @pat_strip_heading_name=/<a name="h?\d.*?">(.+?)<\/a>/
67 @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) if @md
68 end
69 def songsheet
70 if (@md.opt.act[:verbose][:set]==:on \
71 || @md.opt.act[:verbose_plus][:set]==:on \
72 || @md.opt.act[:maintenance][:set]==:on)
73 SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Toc').txt_grey
74 end
75 toc=nil
76 @toc=[]
77 @data.each do |txt|
78 if txt.is ==:heading \
79 || txt.is ==:heading_insert
80 txt.obj=txt.obj.gsub(/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]}).+?(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,''). #remove endnotes from toc
81 gsub(/<a name="-\d+" href="#_\d+">&nbsp;<sup>\d+<\/sup>&nbsp;<\/a>/,'').
82 gsub(@pat_strip_heading_name,'\1')
83 #gsub(/(.*?)<a name="(\d+)"><\/a>(.*)/,'\1') #2002w42 altered gsub - problematic? - suspect
84 toc=case txt.ln
85 when 0 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_0
86 when 1 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_1
87 when 2 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_2
88 when 3 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_3
89 when 4 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_4
90 when 5 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_5
91 when 6 then SiSU_HTML_MiniToc::TocMini.new(@md,txt).level_6
92 else
93 end
94 @toc << toc
95 end
96 end
97 @toc
98 end
99 protected
100 def level_concordance
101 format_head_toc=SiSU_HTML_Format::HeadToc.new(@md)
102 @@seg_mini << format_head_toc.mini_seg_concordance
103 end
104 def level_metadata
105 format_head_toc=SiSU_HTML_Format::HeadToc.new(@md)
106 @@seg_mini << format_head_toc.mini_seg_metadata
107 end
108 def level_word_index
109 format_head_toc=SiSU_HTML_Format::HeadToc.new(@d0c)
110 @@seg_mini << format_head_toc.mini_concordance
111 end
112 def level_0
113 txt=@data
114 if (txt.is ==:heading \
115 || txt.is ==:heading_insert) \
116 && txt.ocn !=0
117 txt.obj=txt.obj.gsub(@pat_strip_heading_name,'\1')
118 end
119 txt_obj={ txt: txt.obj }
120 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
121 toc_mini=format_toc.mini_lev0
122 toc_mini
123 end
124 def level_1
125 txt=@data
126 if (txt.is ==:heading \
127 || txt.is ==:heading_insert) \
128 && txt.ocn !=0
129 txt.obj=txt.obj.gsub(@pat_strip_heading_name,'\1')
130 end
131 title=unless txt.obj =~/Document Information/ then txt.obj
132 else
133 link='metadata'
134 %{<b><a href="#{link}#{@md.lang_code_insert}#{Sfx[:html]}">#{txt.obj}</a></b>}
135 end
136 txt_obj={ txt: title }
137 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
138 toc_mini=if txt.name =~/^meta/ \
139 and txt.obj=~/Document Information/
140 format_toc.mini_tail
141 else format_toc.mini_lev1
142 end
143 toc_mini
144 end
145 def level_2
146 txt=@data
147 if (txt.is ==:heading \
148 || txt.is ==:heading_insert) \
149 && txt.ocn !=0
150 txt.obj=txt.obj.gsub(@pat_strip_heading_name,'\1')
151 end
152 txt_obj={ txt: txt.obj }
153 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
154 toc_mini=format_toc.mini_lev2
155 toc_mini
156 end
157 def level_3
158 txt=@data
159 txt_obj={ txt: txt.obj }
160 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
161 toc_mini=format_toc.mini_lev3
162 toc_mini
163 end
164 def level_4
165 txt=@data
166 unless txt =~/~metadata/
167 if txt.ln ==4
168 fnh={
169 fn: txt.name,
170 }
171 f=@md.file.base_filename.html_seg(fnh)
172 seg_link=%{ <a href="#{f}" target="_top">
173 #{txt.obj}
174 </a> }
175 @@seg_url=txt.name
176 elsif txt.obj =~/\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+/
177 fn,hd=/^(\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+)(.*)/.match(dob.obj)[1,2]
178 fnh={
179 fn: fn,
180 }
181 f=@md.file.base_filename.html_seg(fnh)
182 seg_link=%{<a href="#{f}" target="_top">#{fn} #{hd}</a> }
183 end
184 txt_obj={ txt: seg_link }
185 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
186 toc_mini=format_toc.mini_lev4
187 toc_mini
188 end
189 end
190 def level_5
191 txt=@data
192 if (txt.is ==:heading \
193 || txt.is ==:heading_insert) \
194 && txt.ocn !=0
195 txt.obj=txt.obj.gsub(@pat_strip_heading_name,'\1')
196 end
197 fnh={
198 fn: @@seg_url,
199 }
200 f=@md.file.base_filename.html_seg(fnh)
201 lnk_n_txt=%{ <a href="#{f}##{txt.ocn}">
202 #{txt.obj}
203 </a>}
204 txt_obj={ txt: lnk_n_txt }
205 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
206 toc_mini=format_toc.mini_lev5
207 toc_mini
208 end
209 def level_6
210 txt=@data
211 if (txt.is ==:heading \
212 || txt.is ==:heading_insert) \
213 && txt.ocn !=0
214 txt.obj=txt.obj.gsub(@pat_strip_heading_name,'\1')
215 end
216 fnh={
217 fn: @@seg_url,
218 }
219 f=@md.file.base_filename.html_seg(fnh)
220 lnk_n_txt=%{ <a href="#{f}##{txt.ocn}">
221 #{txt.obj}
222 </a>}
223 txt_obj={ txt: lnk_n_txt }
224 format_toc=SiSU_HTML_Format::FormatToc.new(@md,txt_obj)
225 toc_mini=format_toc.mini_lev6
226 toc_mini
227 end
228 end
229 end
230 __END__