d: html, segments, reorganize, introduce new file
[software/sisu] / lib / sisu / develop / html_segments.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** html segment generation, processing
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_segments.rb;hb=HEAD>
55
56 =end
57 module SiSU_HTML_Seg
58 require_relative 'html_shared' # html_shared.rb
59 require_relative 'html' # html.rb
60 require_relative 'html_persist' # html_persist.rb
61 require_relative 'html_promo' # html_promo.rb
62 require_relative 'shared_metadata' # shared_metadata.rb
63 class Output
64 def initialize(md,outputfile,per,minitoc,type='')
65 @md, @output_seg_file,@per,@minitoc,@type=
66 md,outputfile, per,minitoc, type
67 @title_banner_=SiSU_Env::CreateSite.new(@md.opt).html_seg_title_banner?
68 @file=SiSU_Env::FileOp.new(@md)
69 @make=SiSU_Env::ProcessingSettings.new(@md)
70 @cl=(@make.build.html_minitoc?) \
71 ? 'content'
72 : 'content0'
73 end
74 def output
75 if @per.title =~/\S/
76 filename_seg=[]
77 if @make.build.html_top_band?
78 filename_seg \
79 << @per.title \
80 << @per.tocband_banner
81 else
82 filename_seg \
83 << @per.title
84 end
85 if @type=='endnotes'
86 @per.headings=[]
87 format_head_seg=SiSU_HTML_Format::HeadSeg.new(@md)
88 if @title_banner_
89 @per.headings \
90 << format_head_seg.
91 title_banner(@md.title.main,@md.title.sub,@author)
92 end
93 txt_obj={ txt: 'Endnotes', ocn_display: '' }
94 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
95 @per.headings \
96 << format_seg.title_heading1
97 filename_seg \
98 << @per.heading_endnotes \
99 << @minitoc << @per.headings \
100 << %{\n<div class="#{@cl}">\n} \
101 << @per.endnote_all \
102 << '</div>' # << '</div>'
103 elsif @type=='idx'
104 @per.headings=[]
105 format_head_seg=SiSU_HTML_Format::HeadSeg.new(@md)
106 if @title_banner_
107 @per.headings \
108 << format_head_seg.
109 title_banner(@md.title.main,@md.title.sub,@author)
110 end
111 txt_obj={ txt: 'Index', ocn_display: '' }
112 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
113 @per.headings << format_seg.title_heading1
114 filename_seg \
115 << @per.heading_idx \
116 << @minitoc << @per.headings \
117 << %{\n<div class="#{@cl}">\n} \
118 << @per.idx \
119 << '</div>' # << '</div>'
120 elsif @type=='metadata'
121 metadata=SiSU_Metadata::Summary.new(@md).html_display.metadata
122 @per.headings=[]
123 format_head_seg=SiSU_HTML_Format::HeadSeg.new(@md)
124 if @title_banner_
125 @per.headings \
126 << format_head_seg.
127 title_banner(@md.title.main,@md.title.sub,@author)
128 end
129 txt_obj={ txt: 'Metadata', ocn_display: '' }
130 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
131 @per.headings \
132 << format_seg.title_heading1
133 filename_seg \
134 << @per.heading_idx \
135 << @minitoc \
136 << @per.headings \
137 << %{\n<div class="#{@cl}">\n} \
138 << metadata \
139 << '</div>' # << '</div>'
140 else
141 if @make.build.html_top_band?
142 filename_seg \
143 << @minitoc \
144 << @per.headings \
145 << @per.main \
146 << "\n</div>\n"
147 else
148 filename_seg \
149 << @minitoc \
150 << @per.main \
151 << "\n</div>\n"
152 end
153 end
154 filename_seg <<=if @make.build.html_top_band?
155 @per.tail \
156 << @per.tocband_bannerless \
157 << @per.credits
158 else
159 @per.tail \
160 << @per.credits
161 end
162 filename_seg=filename_seg.flatten.compact #watch
163 filename_seg.each do |str|
164 unless str =~/\A\s*\Z/
165 str=str.strip.
166 gsub(Xx[:html_relative2],
167 @file.path_rel_links.html_seg_2).
168 gsub(Xx[:html_relative1],
169 @file.path_rel_links.html_seg_1)
170 @output_seg_file << str
171 end
172 end
173 @output_seg_file.close
174 end
175 end
176 end
177 class Seg
178 @@seg_url=''
179 @@tracker=0
180 @@seg_name=[]
181 attr_reader :seg_name_x,:seg_name_x_tracker
182 def initialize(md=nil,data='')
183 @md,@data=md,data
184 @per=SiSU_HTML_Persist::Persist.new
185 @seg_name_x=@per.seg_name_x=(@@seg_name || [])
186 @seg_name_x_tracker=@per.seg_name_x_tracker=(@@tracker || 0)
187 @env=SiSU_Env::InfoEnv.new(@md.fns) if @md
188 if @md
189 @make=SiSU_Env::ProcessingSettings.new(@md)
190 @cl=(@make.build.html_minitoc?) \
191 ? 'content'
192 : 'content0'
193 else @cl='content'
194 end
195 if @md
196 @title_banner_=SiSU_Env::CreateSite.new(@md.opt).html_seg_title_banner?
197 end
198 end
199 def songsheet
200 begin
201 @minitoc=SiSU_HTML::Source::Toc.new(@md,@data).minitoc
202 SiSU_HTML_Persist::Persist.new.persist_init
203 @per=SiSU_HTML_Persist::Persist.new
204 data=get_subtoc_endnotes(@data,@per)
205 data=articles(data,@per)
206 cleanup(@md,@per) # (((( added ))))
207 #### (((( END )))) ####
208 rescue
209 SiSU_Errors::Rescued.new($!,$@,@md.opt.selections.str,@md.fns).location do
210 __LINE__.to_s + ':' + __FILE__
211 end
212 ensure
213 @@seg_name=@per.seg_name=[]
214 end
215 end
216 protected
217 def articles(data,per)
218 @per=per
219 tracking,newfile=0,0
220 printed_endnote_seg='n'
221 idx_html=nil
222 if @md.book_idx
223 #my_make_source_file=SiSU_Env::CreateFile.new(@md.fns)
224 idx_html=SiSU_Particulars::CombinedSingleton.
225 instance.get_idx_html(@md.opt).html_idx
226 idx_html.each do |x|
227 @per.idx << x
228 end
229 @per.heading_idx=''
230 end
231 data.each do |dob|
232 if (dob.is == :heading \
233 || dob.is == :heading_insert) \
234 && dob.ln == 4
235 @@seg_name << dob.name
236 @per.seg_name = @@seg_name
237 dob.name
238 end
239 end
240 @per.seg_name_x=@per.seg_name
241 @per.seg_name.length
242 testforartnum=@per.seg_name_x
243 if (@md.opt.act[:verbose][:set]==:on \
244 || @md.opt.act[:verbose_plus][:set]==:on \
245 || @md.opt.act[:maintenance][:set]==:on)
246 SiSU_Screen::Ansi.new(
247 @md.opt.act[:color_state][:set],
248 @per.seg_name.length
249 ).segmented
250 end
251 map_nametags=SiSU_Particulars::CombinedSingleton.
252 instance.get_map_nametags(@md).nametags_map #p map_nametags
253 data.each do |dob|
254 if defined? dob.obj \
255 and dob.obj =~/href="#{Xx[:segment]}#+\S+?"/
256 while dob.obj =~/href="#{Xx[:segment]}#+(\S+?)"/
257 m=$1
258 if map_nametags[m] \
259 and map_nametags[m][:segname]
260 inf=SiSU_Env::FileOp.new(@md) if @md
261 lng=(inf.output_dir_structure.by_language_code?) \
262 ? ''
263 : '.' + @md.opt.lng
264 dob.obj.sub!(/href="#{Xx[:segment]}#+(\S+?)"/,
265 %{href="#{map_nametags[m][:segname]}#{lng}#{Sfx[:html]}#\\1"})
266 else
267 p "NOT FOUND name_tags: #{m}"
268 dob.obj.sub!(/href="#{Xx[:segment]}#+(\S+?)"/,
269 %{href="#\\1"}) # not satisfactory
270 end
271 end
272 end
273 if (dob.is==:heading \
274 || dob.is==:heading_insert) \
275 && dob.ln==4
276 @per.heading4=dob.obj
277 @per.is4=newfile=1
278 end
279 if (dob.is==:heading \
280 || dob.is==:heading_insert) \
281 && dob.ln==3
282 @per.heading3=dob.obj
283 @per.is4,@per.is3=0,1
284 end
285 if (dob.is==:heading \
286 || dob.is==:heading_insert) \
287 && dob.ln==2
288 @per.heading2=dob.obj
289 @per.is4,@per.is3,@per.is2=0,0,1
290 end
291 if (dob.is==:heading \
292 || dob.is==:heading_insert) \
293 && dob.ln==1
294 @per.heading1=dob.obj
295 @per.is4,@per.is3,@per.is2,@per.is1=0,0,0,1
296 end
297 if (dob.is==:heading \
298 || dob.is==:heading_insert) \
299 && dob.ln==0
300 @per.heading0=dob.obj
301 @per.is4,@per.is3,@per.is2,@per.is1,@per.is0=0,0,0,0,1
302 end
303 if (@per.is1 && !@per.is2 && !@per.is3 && !@per.is4)
304 if not (dob.is==:heading \
305 || dob.is==:heading_insert) \
306 && dob.ln==0
307 $_ #; check
308 end
309 end
310 if @per.is4==1
311 if newfile==1 \
312 or dob.obj =~/^#{Mx[:br_endnotes]}|^#{Mx[:br_eof]}/
313 newfile=0
314 if (dob.is==:heading \
315 || dob.is==:heading_insert) \
316 && dob.ln==4
317 if tracking != 0
318 @file=SiSU_Env::FileOp.new(@md)
319 unless FileTest.directory?(@file.output_path.html_seg.dir)
320 FileUtils::mkdir_p(@file.output_path.html_seg.dir) \
321 if File.writable?("#{@file.output_path.base.dir}/.")
322 end
323 tail(@md,@per)
324 #SiSU_HTML_Seg::Seg.new(@md,@per).tail
325 fnh={
326 fn: @per.seg_name_x[tracking-1],
327 }
328 fn=@md.file.base_filename.html_seg(fnh)
329 segfilename="#{@file.output_path.html_seg.dir}/#{fn}"
330 output_seg_file=File.new(segfilename,'w') if @per.seg_name_x[tracking-1]
331 minitoc=(@make.build.html_minitoc?) ? @minitoc : ''
332 if dob.is==:heading \
333 || (@per.seg_name_x[tracking-1] !~/endnotes|book_index|metadata/)
334 SiSU_HTML_Seg::Output.new(@md,output_seg_file,@per,minitoc).output
335 elsif dob.is==:heading_insert
336 if @per.seg_name_x[tracking-1]=='endnotes'
337 SiSU_HTML_Seg::Output.new(@md,output_seg_file,@per,minitoc,'endnotes').output
338 elsif @per.seg_name_x[tracking-1]=='book_index'
339 SiSU_HTML_Seg::Output.new(@md,output_seg_file,@per,minitoc,'idx').output
340 @per.idx=[]
341 elsif @per.seg_name_x[tracking-1]=='metadata'
342 SiSU_HTML_Seg::Output.new(@md,output_seg_file,@per,minitoc,'metadata').output
343 else puts "#{__FILE__}::#{__LINE__}"
344 end
345 else puts "#{__FILE__}::#{__LINE__}"
346 end
347 SiSU_HTML_Seg::Seg.new.reinitialise(per)
348 #per=persist_init
349 heading_art(dob)
350 head(dob)
351 #keep use for last segment, eg if metadata is last segment
352 if @per.seg_name_x[tracking] =='metadata' # this is for metadata
353 fnh={
354 fn: @per.seg_name_x[tracking],
355 }
356 fn=@md.file.base_filename.html_seg(fnh)
357 segfilename="#{@file.output_path.html_seg.dir}/#{fn}"
358 output_seg_file=File.new(segfilename,'w')
359 SiSU_HTML_Seg::Output.new(@md,output_seg_file,@per,minitoc,'metadata').output
360 #per=persist_init
361 Seg.new.reinitialise(per)
362 end
363 end
364 if tracking==0
365 heading_art(dob)
366 head(dob)
367 end
368 end
369 tracking=tracking+1
370 end
371 if (dob.is==:heading \
372 || dob.is==:heading_insert) \
373 && dob.ln==4 \
374 && dob.name
375 @per.get_hash_to=dob.name
376 @per.get_hash_fn=dob.name
377 end
378 if dob.obj.is_a?(String)
379 markup(dob)
380 elsif dob.obj.is_a?(Array)
381 dob.obj.each do |pg|
382 markup(pg)
383 end
384 end
385 if testforartnum[tracking-1] =~/endnote/
386 if printed_endnote_seg=='n'
387 printed_endnote_seg='y'
388 end
389 end
390 end
391 end
392 data
393 end
394 def heading_art(dob)
395 format_head_seg=SiSU_HTML_Format::HeadSeg.new(@md)
396 @per.dot_nav=if (@make.build.html_navigation?) \
397 && (@make.build.html_navigation_bar?)
398 x=if (dob.is==:heading \
399 || dob.is==:heading_insert) \
400 && (dob.ln.to_s =~/^[0-7]/)
401 x=if @@tracker < @per.seg_name.length-1
402 format_head_seg.dot_control_pre_next
403 else
404 format_head_seg.dot_control_pre
405 end
406 else @per.dot_nav
407 end
408 else @per.dot_nav=''
409 end
410 ads=SiSU_HTML_Promo::Ad.new(@md)
411 @per.title=format_head_seg.head_seg << ads.div.major
412 end
413 def head(dob)
414 clean=/<!.*?!>|<:.*?>/
415 format_head_seg=SiSU_HTML_Format::HeadSeg.new(@md)
416 if @make.build.html_navigation?
417 if @@tracker < @per.seg_name.length-1
418 @per.segtocband=if @@tracker==0
419 format_head_seg.toc_next2
420 else
421 format_head_seg.toc_pre_next2
422 end
423 else @per.segtocband=format_head_seg.toc_pre2
424 end
425 else @per.segtocband=''
426 end
427 @p_num ||= ''
428 if @per.is0==1
429 @author=%{<b>#{@md.author}</b>\n} if @md.author.to_s =~/\S/
430 @per.tocband_banner \
431 << format_head_seg.navigation_band(@per.segtocband,@per.dot_nav)
432 @per.tocband_bannerless \
433 << '<br>' \
434 << format_head_seg.navigation_band_bottom(@per.segtocband,@per.dot_nav)
435 if @title_banner_
436 @per.headings \
437 << format_head_seg.title_banner(@md.title.main,@md.title.sub,@author).gsub(clean,'')
438 end
439 ocn=(@per.heading0[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \
440 ? $1
441 : ''
442 @p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
443 txt_obj={ txt: @per.heading0, ocn_display: @p_num.ocn_display }
444 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
445 @per.headings \
446 << format_seg.title_heading0.gsub(clean,'')
447 @per.heading0=@per.heading0.
448 gsub(/&nbsp;<a name="-[\d*+]+" href="#_[\d*+]+">&nbsp;<sup>[\d*+]+<\/sup>&nbsp;<\/a>/,'')
449 end
450 if @per.is1==1
451 heading1=@per.heading1
452 ocn=(heading1[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \
453 ? $1
454 : ''
455 @p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
456 txt_obj={ txt: heading1, ocn_display: @p_num.ocn_display }
457 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
458 @per.headings \
459 << format_seg.title_heading1.gsub(clean,'')
460 @per.heading1=@per.heading1.
461 gsub(/&nbsp;<a name="-[\d*+]+" href="#_[\d*+]+">&nbsp;<sup>[\d*+]+<\/sup>&nbsp;<\/a>/,'')
462 end
463 if @per.is2==1
464 heading2=@per.heading2
465 ocn=(heading2[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \
466 ? $1
467 : ''
468 @p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
469 txt_obj={ txt: heading2, ocn_display: @p_num.ocn_display }
470 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
471 @per.headings \
472 << format_seg.title_heading2.gsub(clean,'')
473 @per.heading2=@per.heading2.
474 gsub(/&nbsp;<a name="-[\d*+]+" href="#_[\d*+]+">&nbsp;<sup>[\d*+]+<\/sup>&nbsp;<\/a>/,'')
475 end
476 if @per.is3==1
477 heading3=@per.heading3
478 ocn=(heading3[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \
479 ? $1
480 : ''
481 @p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
482 txt_obj={ txt: heading3, ocn_display: @p_num.ocn_display }
483 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
484 @per.headings \
485 << format_seg.title_heading3.gsub(clean,'')
486 @per.heading3=@per.heading3.
487 gsub(/&nbsp;<a name="-[\d*+]+" href="#_[\d*+]+">&nbsp;<sup>[\d*+]+<\/sup>&nbsp;<\/a>/,'')
488 end
489 if @per.is4==1
490 heading4=@per.heading4
491 ocn=(heading4[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \
492 ? $1
493 : ''
494 @p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,ocn)
495 txt_obj={ txt: heading4, ocn_display: @p_num.ocn_display }
496 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
497 @per.headings \
498 << format_seg.title_heading4.gsub(clean,'')
499 end
500 @@tracker=@@tracker+1
501 end
502 def markup(dob)
503 @debug=[]
504 SiSU_HTML_Format::HeadSeg.new(@md)
505 if dob.is !=:meta
506 if dob.is==:heading \
507 || dob.is==:heading_insert \
508 || dob.is == :para
509 @p_num=SiSU_HTML_Format::ParagraphNumber.new(@md,dob.ocn)
510 end
511 sto=SiSU_HTML_Format::FormatTextObject.new(@md,dob)
512 dob_html=if dob.is == :heading \
513 || dob.is==:heading_insert \
514 || dob.is==:para
515 dob_html=if dob.is==:heading \
516 || dob.is==:heading_insert
517 if dob.ln==4
518 sto.seg_heading4
519 elsif dob.ln==5
520 sto.seg_heading5
521 elsif dob.ln==6
522 sto.seg_heading6
523 elsif dob.ln==7
524 sto.seg_heading6
525 end
526 elsif dob.is==:para
527 if dob.indent \
528 and dob.hang \
529 and dob.indent =~/[0-9]/ \
530 and dob.hang =~/[0-9]/
531 if dob.bullet_
532 if dob.indent =~/[1-9]/
533 sto.format('li',"i#{dob.indent}")
534 else
535 sto.format('li','bullet')
536 end
537 elsif dob.indent == dob.hang
538 sto.format('p',"i#{dob.indent}")
539 elsif dob.indent != dob.hang
540 sto.format('p',"h#{dob.hang}i#{dob.indent}")
541 else sto.para
542 end
543 else sto.para
544 end
545 end
546 elsif dob.is==:block
547 sto.block
548 elsif dob.is==:group
549 sto.group
550 elsif dob.is==:alt
551 sto.alt
552 elsif dob.is==:verse
553 sto.verse
554 elsif dob.is==:code
555 sto.code
556 elsif dob.is==:table
557 sto.table
558 elsif dob.is==:break \
559 and dob.from==:markup
560 '<br><hr width=90% /><br>'
561 end
562 if @md.flag_separate_endnotes
563 dob.obj=dob.obj.gsub(/"\s+href="#(#{Mx[:note]}\d+)">/,%{" href=\"endnotes#{Sfx[:html]}#\\1">}) #endnote- twice #removed file type
564 end
565 if (dob.is==:heading \
566 || dob.is==:heading_insert \
567 || dob.is==:para) \
568 && (not dob.ocn \
569 || (dob.ocn.to_s.empty?))
570 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,dob)
571 end
572 dob.obj=dob.obj.gsub(/\s*(-\{{2}~\d+|<:e[:_]\d+>).*/,'') #potentially dagerous - removes all paragraphs with <!e_!> #?? workpoint
573 if dob.obj =~/<a name="_\d+" href="#-\d+">&nbsp;<sup>/ #endnote- note-
574 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,dob)
575 dob=format_seg.no_paranum
576 end
577 if (dob.is==:heading \
578 || dob.is==:heading_insert) \
579 && dob.ln==4
580 @per.main << %{\n<div class="#{@cl}">\n}
581 @per.main << dob_html
582 if @make.build.segsubtoc?
583 @per.main << @per.seg_subtoc[@per.get_hash_fn] #% insertion of sub-toc
584 end
585 else
586 @per.main << dob_html #unless @@flag_alt==true
587 end
588 end
589 end
590 def tail(md,per)
591 @md,@per=md,per
592 format_head_seg=SiSU_HTML_Format::HeadSeg.new(@md)
593 if @md.flag_auto_endnotes \
594 and @per.seg_endnotes[@per.get_hash_fn]
595 @per.tail << %{\n<div class="#{@cl}">\n<div class="endnote">\n}
596 if @per.seg_endnotes[@per.get_hash_fn].flatten.length > 0
597 @per.tail << format_head_seg.endnote_mark
598 @per.tail << @per.seg_endnotes[@per.get_hash_fn].flatten #endnotes deposited at end of individual segments ||@|EXTRACTION OF ENDNOTES|
599 end
600 @per.tail << '</div>'
601 @per.tail << '</div>' #this div closes div class content
602 end
603 ads=SiSU_HTML_Promo::Ad.new(@md)
604 @per.credits \
605 << format_head_seg.credit \
606 << ads.div.close \
607 << ads.display \
608 << format_head_seg.html_close
609 end
610 def reinitialise(per)
611 per.title,per.dot_nav,per.tocband_banner,per.tocband_bannerless,per.headings,per.main,per.tail,per.credits=Array.new(8){[]}
612 @per.segtocband=nil
613 end
614 def cleanup(md,per)
615 #per=persist_init
616 reinitialise(per)
617 @@tracker=0
618 @per.seg_endnotes,@per.seg_subtoc={},{}
619 @per.seg_endnotes_array,@per.seg_subtoc_array=[],[]
620 per.endnote_all=[]
621 end
622 def get_subtoc_endnotes(data,per) #get endnotes & sub-table of contents subtoc
623 @per=per
624 data.each do |dob|
625 dob.obj=dob.obj.gsub(/<a name=\"h\d.*?\">(.+?)<\/a>/mi,'\1')
626 if @md.flag_auto_endnotes
627 if (dob.is==:heading \
628 || dob.is==:heading_insert) \
629 && (dob.ln.to_s =~/^[0-4]/) \
630 and not @per.fn.to_s.empty?
631 @per.seg_endnotes[@per.fn]=[]
632 @per.seg_endnotes[@per.fn] << @per.seg_endnotes_array
633 @per.seg_endnotes_array=[] if dob.ln==4
634 end
635 if (dob.is==:heading \
636 || dob.is==:heading_insert) \
637 && dob.ln==4 #% EXTRACTION OF SUB-TOCs & SEGMENT NAME, after EXTRACTION OF ENDNOTES & SUB-TOCs
638 @per.seg_subtoc[@per.fn]=@per.seg_subtoc_array
639 @per.seg_subtoc_array=[]
640 if dob.name \
641 and dob.obj
642 @per.fn=dob.name
643 else
644 if dob.name =~/\S+/
645 @per.fn=dob.name
646 else @per.fn=''
647 end
648 end
649 end
650 end
651 if dob.is==:heading \
652 && (dob.ln.to_s =~/^[5-7]/)
653 case dob.ln
654 when 5
655 txt_obj={ txt: dob.obj.strip, ocn: dob.ocn }
656 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
657 subtoc=format_seg.subtoc_lev5 #keep and make available, this is the subtoc
658 when 6
659 txt_obj={ txt: dob.obj.strip, ocn: dob.ocn }
660 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
661 subtoc=format_seg.subtoc_lev6 #keep and make available, this is the subtoc
662 when 7
663 txt_obj={ txt: dob.obj.strip, ocn: dob.ocn }
664 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
665 subtoc=format_seg.subtoc_lev7 #keep and make available, this is the subtoc
666 end
667 @per.seg_subtoc_array << subtoc
668 end
669 if @md.flag_auto_endnotes
670 if (dob.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})[\d*+]+\s*<a href="##{Mx[:note_ref]}[\d*+]+"/) \
671 && dob.is !=:code # endnote-
672 endnote_array=[]
673 if dob.obj=~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m
674 endnote_array << dob.obj.scan(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m)
675 end
676 if dob.obj=~/#{Mx[:en_b_o]}[*]\d+\s.+?#{Mx[:en_b_c]}/m
677 endnote_array \
678 << dob.obj.scan(/#{Mx[:en_b_o]}[*]\d+\s.+?#{Mx[:en_b_c]}/m)
679 end
680 if dob.obj=~/#{Mx[:en_b_o]}[+]\d+\s.+?#{Mx[:en_b_c]}/m
681 endnote_array \
682 << dob.obj.scan(/#{Mx[:en_b_o]}[+]\d+\s.+?#{Mx[:en_b_c]}/m)
683 end
684 endnote_array=endnote_array.flatten.compact #watch, check compacting
685 endnote_array.each do |note|
686 note_match=note.dup
687 note_match_seg=note.dup
688 e_n=note_match_seg[/(?:#{Mx[:en_a_o]}[\d*+]+|#{Mx[:en_b_o]}[*+]\d+)\s+(.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,1]
689 try=e_n.split(/<br(?: \/)?>/)
690 try.each do |e|
691 txt_obj={ txt: e }
692 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
693 note_match=if e =~/#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}/
694 format_seg.endnote_body_indent
695 else format_seg.endnote_body
696 end
697 @per.seg_endnotes_array << note_match
698 end
699 try.join('<br>')
700 #% creation of separate end segment/page of all endnotes referenced back to reference segment
701 m=/(?:#{Mx[:en_a_o]}[\d*+]+|#{Mx[:en_b_o]}[*+]\d+)\s+(.+?href=")(##{Mx[:note_ref]}[\d*+]+".+)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/mi
702 endnote_part_a=note_match_seg[m,1]
703 endnote_part_b=note_match_seg[m,2]
704 txt_obj={ endnote_part_a: endnote_part_a, endnote_part_b: endnote_part_b }
705 format_seg=SiSU_HTML_Format::FormatSeg.new(@md,txt_obj)
706 note_match_all_seg=format_seg.endnote_seg_body(@per.fn) #BUG WATCH 200408
707 @per.endnote_all << note_match_all_seg
708 end
709 dob.obj=dob.obj.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ')
710 end
711 end
712 end
713 end
714 end
715 end
716 __END__